Using AJAX to pass variable to PHP and retrieve those using AJAX again

前端 未结 5 1959
别跟我提以往
别跟我提以往 2020-11-30 06:41

I want to pass values to a PHP script so i am using AJAX to pass those, and in the same function I am using another AJAX to retrieve those values.

The problem is th

5条回答
  •  攒了一身酷
    2020-11-30 07:40

    Use dataType:"json" for json data

    $.ajax({
         url: 'ajax.php', //This is the current doc
         type: "POST",
         dataType:'json', // add json datatype to get json
         data: ({name: 145}),
         success: function(data){
             console.log(data);
         }
    });  
    

    Read Docs http://api.jquery.com/jQuery.ajax/

    Also in PHP

     where color='".$userAnswer."'" ;
      $result=mysql_query($sql);
      $row=mysql_fetch_array($result);
      // for first row only and suppose table having data
      echo json_encode($row);  // pass array in json_encode  
    ?>
    

提交回复
热议问题