【发布时间】:2015-08-19 01:37:32
【问题描述】:
使用 $.post(),我试图将 $.cookie('pear') 的值发送到我的 PHP 表单,它会用它做一些事情。但问题是,PHP 表单似乎无法接收$.cookie('pear') 的值。
需要明确的是,$.cookie('pear') 绝对有价值。我做了一个alert($.cookie('pear')) 仔细检查,它肯定显示了$.cookie('pear') 的值。
在下面查看我的代码。感谢您指出它有什么问题的帮助。也许我的 $.post() 实现有问题?
jQuery
submit_fruit.on({
click: function () {
$('#market').click();
var pears = $.cookie('pears')
alert(pears) // this works. it alert the value of the cookie 'pears'
$.post('fruitsubmission.php', { pears: pears }, function(data) {
}); // but this troublesome piece of $.post() doesn't seem to send 'pears' over to the PHP form.
}
});
PHP
$fruit = $_POST['pears'];
echo $fruit;
-- some mySQL data submissions stuff here --
但我无法获得从 $.post() 调用发送过来的值 'pears'。
错误报告
Notice: Undefined index: pears in ******* on line 10
【问题讨论】:
-
为什么在
$.post('#fruitsubmission.php', ...中使用#字符?像这样使用它具有发布到发起请求的页面的效果。这是你的意图吗? -
抱歉,这是我的疏忽。我的意思是没有标签。不过,我仍然收到相同的错误报告。
-
如果你设置
var pears = "this is a test";你会得到同样的错误吗?
标签: jquery cookies http-post postback