javascript - POST without redirecting page - Stack Overflow

HiI am writing an application where I want to post data after clicking send button, it will post data

Hi I am writing an application where I want to post data after clicking send button, it will post data to some web-action and gets processed, after processing it will be redirected to some other jsp page but I want to be in the same page from where I click send button. I am not sure of XMLHttpRequest method.

Any ideas to get this done highly appreciated.

Hi I am writing an application where I want to post data after clicking send button, it will post data to some web-action and gets processed, after processing it will be redirected to some other jsp page but I want to be in the same page from where I click send button. I am not sure of XMLHttpRequest method.

Any ideas to get this done highly appreciated.

Share asked Jan 13, 2011 at 5:40 girigiri 27.3k65 gold badges147 silver badges180 bronze badges 3
  • 1 What's the problem with just forwarding/redirecting to the same page? – BalusC Commented Jan 13, 2011 at 13:04
  • @BalusC Then when the user decides to hit refresh it asks them... "do you want to submit the form again" – user115422 Commented Aug 20, 2012 at 18:06
  • @MuqMan: that only applies if you're forwarding instead of redirecting, regardless of the target page. This is pletely unrelated to what's been asked here, by the way. – BalusC Commented Aug 20, 2012 at 18:19
Add a ment  | 

7 Answers 7

Reset to default 3

If you wanna do using Java script and Ajax (As you have in your question tags) then Try following:

 function fun() {
  if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  } else {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  var url = "Serv?req_id=1";
  xmlhttp.open("POST", url, false);
  xmlhttp.send(null);
  var respo= xmlhttp.responseText;
  document.getElementById("some_id").innerHTML = xmlhttp.responseText;
 }

Call fun() on onclick event of send button.

Hope this helps.

You can use jQuery.ajax() - it's a convenient wrapper for XMLHttpRequest.

You can use jQuery. It will save some time. It is cross browser patible (i.e. hides the cross browser patibility techniques from you).

http://api.jquery./jQuery.post/

http://jquery./

You can issue a 302 request back to the page you came from as the response from the POST request. If you don't want to POST at all I can show you how to do this through AJAX.

The reason you want to use the GET->POST->GET is so that if the user hits the back button it doesn't re-post on you.

Here's a great beginner's tutorial on what you're looking to do (with jQuery):

http://net.tutsplus./tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

A 302 request back approach seems to be good for this, If you were using ajax or XMLHttpRequest object, it wouldn't be that problem, but here you can set redirection header to redirect back on the same script that process your query-string.

However you cannot do post without a redirection.

Passing values from one jsp page to another jsp page

I know this is a bit late but for the sake of sharing knowledge, I found a good article here: http://net.tutsplus./tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/ On it, is a very thorough example of how to do what you are asking for.

This is done, as mentioned above, with AJAX/jQuery, this tutorial makes use of that.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743687008a4490314.html

相关推荐

  • javascript - POST without redirecting page - Stack Overflow

    HiI am writing an application where I want to post data after clicking send button, it will post data

    6天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信