douduan9129 2016-10-04 01:19
浏览 41
已采纳

发布不在PHP函数中,即使同一函数中的var_dump显示数据

I'm befuddled. I have a JavaScript function that posts to a PHP function. PHP says, "undefined index" on mPicker. Yet if I call var_dump within the same function mPicker is plainly visible.

console.log

I've also ran an alert client side in JavaScript to be sure the form data was serialized, and it too shows that mPicker indeed has a value. Yet this line in PHP returns the error:

$es=$_POST["mPicker"];

This is just short hand for all your sake. The longer version of the code tests for SQL injection.

And the error in xdebug:

php error in xdebug

The JavaScript code:

$.post("./php/adates.php", { atype: apttype, data: $("#apptForm").serialize() })
.done(function(data) {
    alert(data);
});

And more of the php function code:

if (isset($_POST["atype"]) && !empty($_POST["atype"])) {
    $typ = test_input($_POST['atype'], $con);
} else {
    echo "error ln 6: typ is undefined.";
}

$es=$_POST["mPicker"];
echo $es;
exit;

test_input is the function I mentioned that tests for SQL injection, and just for testing, have omitted temporarily on the post on mPicker. As you can see, the line $_POST["atype"] escapes error, and is perfectly resolved in the PHP function. I know I am tired and must be missing something stupid. Help, anyone!

  • 写回答

1条回答 默认 最新

  • duanchandun1860 2016-10-04 01:31
    关注

    try to use jQuery "ajax" instead of "post"

    $.ajax({
      type: 'POST',
      url: url,
      data: data,
      dataType: "html",
      success: function(html){
         console.log(html)
      }
    
    });
    

    and set the dataType to "html", then use "echo" or "var_dunmp" in php, you can see ur data in console

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败