我有一个提交跨域的表单,但页面会返回一些这样的XML:
<response>
<result>12</result>
<message>Invalid parameter.</message>
<error><code>0</code>
<desc>Parameter[first_name] value is empty</desc>
</error>
</response>
我需要使用哪种JQuery Ajax提交表单格式,所以我可以提交表单并获得结果,例如我需要标签中的内容。
答案 0 :(得分:0)
通常这是我使用的Ajax表单提交代码。
$.ajax({
dataType: "json",
method: "POST",
url: 'url',
data: $('#your_form').serialize(),
success: function (data) {
//whatever
}
});
在任何情况下,如果您想要发出跨域请求,您必须更改控制器以允许它。
public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
public static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers";
public static final String ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
public static final String ACCESS_CONTROL_ALLOW_METHODS = "Access-Control-Allow-Methods";
public static final String ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
public static final String ACCESS_CONTROL_ALLOW_METHODS_VALUE = "GET, POST, PUT, OPTIONS";
response.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, request.getHeader(ORIGIN));
response.addHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, ALLOW_CREDENTIALS);