weixin_33733810 2015-06-04 08:17 采纳率: 0%
浏览 9

php未收到Ajax发布

I have written a simple code. In order to avoid flooding a JSON server, i want to break up the JSON response in pieces. So my jquery code should be parsing one variable ("page") to the php page that handles the JSON Oauth Request. On success, it should append the DIV with the latest responses.

My code should be working, except for the fact that my ajax post is not being received by my php file.

Here goes

archief.html

$("#klik").click(function() {
console.log("fire away");
page = page + 1;
$("#archief").load("trytocombinenewageandgettagsendates.php");
 console.log(page);              
                $.ajax({
                    type: 'POST',
                    url: "trytocombinenewageandgettagsendates.php",
                   data:  page,
                    success: function() {

                            console.log(page);

                          $.get("trytocombinenewageandgettagsendates.php", function(archief) {
                                $('#archief').append(archief);
                            });

                    },
                    error: function(err) {
                            alert(err.responseText);
                    } 
                });
                return false;
       });

The php file doesn't receive anything.

var_dump($_POST);

gives me array(0) { }.

Very strange, i'd really appreciate the help!

  • 写回答

2条回答 默认 最新

  • weixin_33713503 2015-06-04 08:23
    关注

    You are sending a string instead of key-value pairs. If you want to use $_POST you need to send key-value pairs:

    ...
    $.ajax({
      type: 'POST',
      url: "trytocombinenewageandgettagsendates.php",
      data:  { 'page': page },
      success: function() {
         ...
    

    If you send a single value or string, you would need to read the raw input.

    Also, you are sending 2 GET requests and 1 POST request to the same file. Is that intentional? Note that only the POST request will have the $_POST variable set.

    评论

报告相同问题?