简体   繁体   中英

how to handle response contents by AJAX

for me it seems impossible but expecting clarification on it. i am sending a request as follow :

 <form action="/name" method="get">
     <input type="text" />
     <input type="submit" />
  </form>

Now action class at server side manipulates & send the response to client, can i handle this response by ajax somehow ??

Yes, but you have to submit it via ajax (XmlHttpRequest) in order to be able to get the response that way.

Using jQuery makes this simple:

$.post("/name", {param:param}, function(data) {

});

In that example you should pass manually each form field as param. In case of bigger forms this is not that good. So you can use serialize():

$.post($("#yourForm").attr("action"),
       $("#yourForm").serialize(),
       responseHandlerFunction);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM