我向發佈數據的頁面getremote.php發出了發佈請求,但$ _POST數組似乎是空的。如果有人能告訴我我做錯了什麼,我將不勝感激。
的JavaScript代碼,以使該請求是
var postdata = "Content-Type: application/x-www-form-urlencoded\n\nedits=" + this.createEditXMLtext(this.editXMLstruct);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
dispmes("processing edits");
xmlhttp.open("POST",userProfile.homeurl + "?remoteurl=" + userProfile.homeurl + "&cmdeditprofile&password=password",false);
xmlhttp.send(postdata);
var response = xmlhttp.responseXML;
其中this.createEditXMLtext(this.editXMLstruct)簡單地創建一個字符串
我還沒有收到這個問題,不要似乎與發佈類似問題的其他人有相同的解決方案。 在userProfile.homeurl +「的PHP代碼是
header("Content-type: text/xml");
$query = '';
foreach($_POST as $key => $value){
$query .= "$key=$value&";
}
echo do_post_request($_GET['remoteurl'] . $qstring,$query);
但是字符串$查詢始終是空的 - 我通過添加回聲$查詢到的文件
數據類型設置你100%肯定'POST'是空的? print_r($ _ POST);'產生了什麼? – 2010-10-23 11:22:10
我想,標題信息必須用兩個\ r \ n而不是\ n分開。 HTTP 1.1規範: 通用消息=開始線 *(消息頭CRLF) CRLF [消息體] 開始線=請求行|狀態行 CRLF = \ r \ n – DrDol 2010-10-23 11:23:25
您當然應該考慮轉到JavaScript框架(如jQuery,Dojo或YUI)來處理您的AJAX請求。 – 2010-10-23 14:23:07