2010-06-16 190 views
1

那麼我希望一切都會最終正常工作。但它當然不是。新的問題是以下消息:XMLHttpRequest請求URI太大(414)

請求URI太大
請求的URL的長度超過此服務器的 容量限制。

我的恐懼是我必須找到另一種傳輸數據的方法,或者是一種解決方案嗎?

代碼XHR功能:

function makeXHR(recordData) 
{ 
if (window.XMLHttpRequest) 
{ 
xmlhttp=new XMLHttpRequest(); 

} 
else 
{// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 

var rowData = "?q=" + recordData; 

xmlhttp.open("POST", "insertRowData.php"+rowData, true); 
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
xmlhttp.setRequestHeader("Content-Length",rowData.length); 
xmlhttp.setRequestHeader("Connection", "close"); 

xmlhttp.onreadystatechange = function() 
{ 
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
    { 
    alert("Records were saved successfully!"); 
    } 
} 

xmlhttp.send(null); 

} 

回答

3

你應該通過send方法在請求主體立柱rowData。因此,不要發佈到"insertRowData.php" + rowData,而要發佈到"insertRowData.php",並將rowData中的數據傳遞到send

我懷疑你的rowData是帶問號的查詢字符串。如果是這樣的話,那麼郵件正文只是rowData沒有前置問號。

編輯:像這樣的東西應該工作:

var body = "q=" + encodeURIComponent(recordData); 
xmlhttp.open("POST", "insertRowData.php", true); 
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
xmlhttp.onreadystatechange = // ... 
xmlhttp.send(body); 
+0

喜。我試過你的代碼,但現在我沒有得到我的PHP腳本中的數據: PHP: $ q = $ _GET [「q」]; \t echo $ q; – user366121 2010-06-16 13:31:45

+0

@usurper:你需要使用'$ _POST'超全局數組:'$ q = $ _POST ['q']; echo htmlspecialchars($ q);' – 2010-06-16 14:26:51

+0

hmmm。這是我使用$ q = $ _POST ['q']後得到的結果:: 未定義變量:q – user366121 2010-06-16 14:48:58

相關問題