简体   繁体   中英

JQuery Ajax post data not arriving

my Ajax post data is not arriving - any clues please.

The data is a serilaized form that "alerts" correctly with all the data using this

 $(document).ready(function() {
 var serial = $('#frm_basket').serialize();
 alert(serial);
 $.ajax({
 url: "basket-calc.php",
 type: "post",
 data: serial,
 success: function(){
  ("#basketTotal").load('basket-calc.php');
  }
  });
});

The alert gives me a string like product=p1&qty=1&product=p2&qty=2

But when I try to php echo out the results on basket-calc.php I get an "empty" array

basket-calc.php:

    $test = $_POST;
print_r($test);

You can debug your request with firebug to make sure what is happening.

替代文字

Also try setting the post type to GET:

type: "GET",

to see if it makes any difference.

try:


$(document).ready(function() {
 var serial = $('#frm_basket').serialize();
 alert(serial);
 $.ajax({
 url: "basket-calc.php",
 type: "post",
 data: serial,
 success: function(result){
  ("#basketTotal").html(result);
  }
  });
});

Also note following points:

  1. make sure basket-calc.php is not returning 404
  2. try sending blank data and echo your response
  3. once you get sample string from server, just attach the real data

hope this helps

If your htaccess is stripping the .php from the , the POST gets converted to GET. I think.

Try and remove .php from your url.

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