开发者

retrieve data send from post ajax req

I need to send large amount of string in a ajax post request to server. If i add it the end of the url, i can get using request.getParameter() method in the server.

But i can't append large string in the url.So i want to send using the method send() of XMLHttpRequest instead of appending it to url.

But i couldn't retrieve the same开发者_开发问答 using request.getParameter() in server.

How to retrieve data send from ajax request in j2ee server? Please guide me.


If you have an ajax intensive webapp, I would suggest using a javascript library (such as jquery) to handle ajax. In jQuery, you could do this as :

$.post("your_url.php", { param1: "value1", param2: "value2" } );


Regardless of whether you are or arent using AJAX, there are limits to the actual length of the Url which changes browser to browser.

It will be better POST all your data. Below is the code to do the same using AJAX:

var http = new XMLHttpRequest(); // Get the correct http object depending on browser
var url = "YOUR_URL.php";
var params = "param1=value1&param2=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);

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜