通过使用strut2 jQuery插件标签将JSON对象发送到Struts 2操作 [英] Send JSON object to Struts 2 action by using strut2 jquery plugin tags
问题描述
我们可以通过json
拦截器将JSON发送到Struts2操作. http://tech.learnerandtutor.com/send-json-object-to-struts-2-action-by-jquery-ajax/.
We can send JSON to Struts2 actions by json
interceptor. There is good sample at http://tech.learnerandtutor.com/send-json-object-to-struts-2-action-by-jquery-ajax/.
json
拦截器要求请求content type
是application/json
或application/json-rpc
,当我们直接使用Ajax时可以设置此请求:
The json
interceptor requires that the requests content type
be application/json
or application/json-rpc
this can be set when we directly use Ajax like:
$.ajax({
url: "writeJSON.action",
data: data1,
dataType: 'json',
contentType: 'application/json',
但是我们正在使用struts 2 jquery插件标签(sj:a
和sj:submit
...),这些标签为我们管理ajax调用.
But we are using struts 2 jquery plugin tags (sj:a
and sj:submit
...) which manage ajax calls for us.
有什么方法可以使用这些标签设置contentType
.
Is there any way that we can set the contentType
with these tags.
我没有为此找到标签属性.
I did not find tag properties for this.
如果未实现,还有其他设置方法.
If it is not implemented is there any other way to set it.
推荐答案
您应将Content-type: application/json
标头设置为$.ajax()
使用的xhr对象.
You should set Content-type: application/json
header to xhr object that is used by the $.ajax()
.
$.ajax({
url: "writeJSON.action",
data: data1,
dataType: 'json',
contentType: 'application/json',
该插件正在使用$.ajaxSubmit()
,应取消这种提交方式,因为它不适用于json数据.
The plugin is using $.ajaxSubmit()
, this kind of submission should be eliminated because it doesn't work with json data.
这篇关于通过使用strut2 jQuery插件标签将JSON对象发送到Struts 2操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!