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.

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?