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 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件