[英]how to handle response contents by AJAX
for me it seems impossible but expecting clarification on it. 对我来说,这似乎是不可能的,但希望对此进行澄清。 i am sending a
request
as follow : 我正在发送以下
request
:
<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 ?? 现在服务器端的动作类可以操作并将
response
发送给客户端,我可以通过ajax
处理该response
吗?
Yes, but you have to submit it via ajax (XmlHttpRequest) in order to be able to get the response that way. 是的,但是您必须通过ajax(XmlHttpRequest)提交它,以便能够以这种方式获得响应。
Using jQuery makes this simple: 使用jQuery使这个变得简单:
$.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():
因此,您可以使用serialize():
$.post($("#yourForm").attr("action"),
$("#yourForm").serialize(),
responseHandlerFunction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.