开发者

how to handle response contents by AJAX

开发者 https://www.devze.com 2023-04-10 14:53 出处:网络
for me it seems impossible but expecting clarification on it.i am sending a request as follow : <form act开发者_如何学Cion=\"/name\" method=\"get\">

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

 <form act开发者_如何学Cion="/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);
0

精彩评论

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

关注公众号