我需要發送大量的字符串在ajax後請求到服務器。如果我將它添加到URL的末尾,我可以在服務器中使用request.getParameter()方法。檢索數據發送從郵政阿賈克斯req
但我不能在url中追加大字符串。因此,我想使用XMLHttpRequest的send()方法發送,而不是將其附加到url。
但我無法檢索服務器中使用request.getParameter()相同。
如何在j2ee服務器中檢索從ajax請求發送的數據? 請指導我。
我需要發送大量的字符串在ajax後請求到服務器。如果我將它添加到URL的末尾,我可以在服務器中使用request.getParameter()方法。檢索數據發送從郵政阿賈克斯req
但我不能在url中追加大字符串。因此,我想使用XMLHttpRequest的send()方法發送,而不是將其附加到url。
但我無法檢索服務器中使用request.getParameter()相同。
如何在j2ee服務器中檢索從ajax請求發送的數據? 請指導我。
無論您是否使用AJAX,對於更改browser to browser的Url的實際長度都有限制。
這將是更好的POST
所有的數據。下面是使用AJAX做同樣的代碼:
var http = new XMLHttpRequest(); // Get the correct http object depending on browser
var url = "YOUR_URL.php";
var params = "param1=value1¶m2=value2";
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() { // Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);
希望這會有所幫助。
如果你有一個ajax密集型web應用程序,我會建議使用一個JavaScript庫(如jquery)來處理ajax。在jQuery中,你可以這樣做的:
$.post("your_url.php", { param1: "value1", param2: "value2" });
BTW ...您將無法檢索使用'用request.getParameter所有的變量(「參數1」);'等等。 – Sumit 2011-03-10 07:32:22