简体   繁体   中英

AJAX Call Return PHP Value Empty

i have a problem about ajax call, i dont get what exactly why i still getting this empty success call. i tried the past solution to solve this but i don't know what the cause of this.

as you can see this my table then when i click the action of update, delete, or, add, even print_r($_POST) it's still empty. 在此处输入图片说明 在此处输入图片说明 then when i go to console i got this error. 在此处输入图片说明 the value of selected attr still send to the php file

heres my code :

 $(document).on('click', '.update', function(){
    var user_ID = $(this).attr('id');

$.ajax({
  url:"datatable/account/fetch_single.php",
  method:"POST",
  data:{user_ID:user_ID},
  dataType:"json",
  success:function(data)
  {
    console.log(data);

    $('#account_modal').modal('show');
    $('#username').prop("disabled", true);
    $('#username').val(data.user_Name);
    $('#email').val(data.user_Email);
    $('#pass').val(data.user_Pass);
    $('#con_pass').val(data.user_Pass);
    $('#level').val(data.level_ID).change();
    $('#status').val(data.user_status).change();
    $('#action').val('Edit');
    $('#operation').val('Edit');
    $('.modal-title').text('Edit Account Info');
    $('#user_ID').val(user_ID);
  }
})
  });

fetch_single.php

include('db.php');
include('function.php');
if(isset($_POST["user_ID"]))
{
    $output = array();
    $statement = $conn->prepare(
        "SELECT * FROM `user_accounts`
        WHERE user_ID = '".$_POST["user_ID"]."' 
        LIMIT 1"
    );
    $statement->execute();
    $result = $statement->fetchAll();
    foreach($result as $row)
    {

        $output["level_ID"] = $row["level_ID"];
        $output["user_Name"] = $row["user_Name"];
        $output["user_Pass"] = decryptIt($row["user_Pass"]);
        $output["user_Email"] = $row["user_Email"];
        $output["user_status"] = $row["user_status"];

    }
    echo json_encode($output);
}

or it's might be the cause of problem is the design template?

i solve this issue, in my requested php file i change my $_POST to $_REQUEST if your data in ajax look like

data:{user_ID:user_ID}  

or

data: "fname="+fname+"&lname="+lname

this might work for you, then if your data look like this data:new FormData(this) maybe you should use this type

 data:{user_ID:user_ID}

to work the request and execute your sql.


but the best solution i got is change your

method:"POST"

to

type:"POST"

to solve this problem.


if your data.success_variable is undefined add

header('Content-type:  application/json.'); 

to your requested php file.

在此处输入图片说明

Related topic: ppumkin5 answer to JQuery Ajax is sending GET instead of POST

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM