skip to Main Content

I want to send some data to the file, and it get the file, but there no data

This is my .js code

var ids = [$(this).parent('.status-menu').prev('td').find('input').val()];
        var status = $(this).find(":selected").text();
        var changeStatusRKO = true;

        $.ajax({
            url: window.location.origin + '\partsOfPages\ajax\changeStatus.php',
            type: "POST",
            data: {
                'ids': ids,
                'status': status,
                'changeStatusRKO': changeStatusRKO,
            },
            success: function () {
                console.log('Success');
            },
            fail: function () {
                console.log('Error');
            },

        })

And this is my php, where I am sending the data

<?php

print_r($_POST);

if(isset($_POST["changeStatusRKO"]) OR isset($_POST["changeStatusRegistrationBusiness"]) OR isset($_POST["changeStatusServiceOneClick"])
    OR isset($_POST["changeStatusAcquiring"]) OR isset($_POST["changeStatusCashDesk"])) {
    $idItem = $_POST["idItem"]; //id строки в одной из пяти таблиц (`banks_to_requests_for_XXX`); массив
    // echo "print_r: "; print_r($idItem); echo "<br>";
    // echo "idItem[0]: " . $idItem[0] . "<br>";

    if(!isset($idItem[0]))
...

But when I send it, there are no parameter in $_POST

2

Answers


  1. Chosen as BEST ANSWER

    I solve this problem. I only need to change this part

    url: window.location.origin + '\partsOfPages\ajax\changeStatus.php',
    

    to this

    url: window.location.origin + '\partsOfPages\ajax\changeStatus',
    

    I removed .php in the end


  2. Use ‘method’ instead of ‘type’. Try this:

        $.ajax({
            url: window.location.origin + '\partsOfPages\ajax\changeStatus.php',
            method: "POST",
            data: {
                ids: ids,
                status: status,
                changeStatusRKO: changeStatusRKO,
            },
            success: function () {
                console.log('Success');
            },
            fail: function () {
                console.log('Error');
            },
    
        })
    

    Also, you can use your browser’s developer tools to see what’s actually being passed to the server. In Chrome, you can go to Inspect > Network tab > Click on your request > Headers tab.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search