0
使用$ .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 --
但我不能拿到從$。員額()調用發送過來的值 '梨'。
錯誤報告
Notice: Undefined index: pears in ******* on line 10
爲什麼在$ .post('#fruitsubmission.php',...''中使用'#'字符?像這樣使用它會影響發送請求的頁面。你的意圖是嗎? –
對不起,這是我的疏忽,我的意思是沒有標籤,我仍然得到相同的錯誤報告。 – blurgoon
如果你設置var varars =「這是一個測試」;你是否得到相同的錯誤? –