[英]Ajax post not received by php
我寫了一個簡單的代碼。 為了避免淹沒JSON服務器,我想分拆JSON響應。 因此,我的jquery代碼應該將一個變量(“頁面”)解析到處理JSON Oauth請求的php頁面。 成功后,應在DIV后面附加最新的回復。
我的代碼應該正常工作,除了我的php文件未收到我的ajax帖子。
開始
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;
});
php文件未收到任何內容。
var_dump($_POST);
給我array(0) { }
。
非常奇怪,我非常感謝您的幫助!
您正在發送字符串而不是鍵值對。 如果要使用$_POST
,則需要發送鍵值對:
...
$.ajax({
type: 'POST',
url: "trytocombinenewageandgettagsendates.php",
data: { 'page': page },
success: function() {
...
如果發送單個值或字符串,則需要讀取原始輸入。
另外,您正在向同一文件發送2個GET請求和1個POST請求。 那是故意的嗎? 請注意,只有POST請求才會設置$_POST
變量。
謝謝您的幫助,不要讓我發表“這仍然行不通”的帖子:)
成功時,我錯誤地加載了“未咨詢”的php文件[$ .get(“ trytocombinenewageandgettagsendates.php”],而是附加了PHP的響應。
下面的工作代碼:
$("#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': page },
success: function(response){
$("#archief").append(response);
},
error: function(err) {
alert(err.responseText);
}
});
return false;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.