Send JSON object to Struts 2 action by using strut2 jquery plugin tags
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拦截器将JSON发送到Struts2动作。 http://tech.learnerandtutor.com/send-json-object-to-struts-2-action-by-jquery-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:
json拦截器要求请求内容类型为application / json或application / json-rpc,这可以在我们直接使用Ajax时设置:
$.ajax({
url: "writeJSON.action",
data: data1,
dataType: 'json',
contentType: 'application/json',
But we are using struts 2 jquery plugin tags (sj:a
and sj:submit
...) which manage ajax calls for us.
但我们正在使用struts 2 jquery插件标签(sj:a和sj:submit ...)来管理我们的ajax调用。
Is there any way that we can set the contentType
with these tags.
有没有办法我们可以用这些标签设置contentType。
I did not find tag properties for this.
我没有找到标签属性。
If it is not implemented is there any other way to set it.
如果没有实现,还有其他任何方式来设置它。
1 个解决方案
#1
2
You should set Content-type: application/json
header to xhr object that is used by the $.ajax()
.
您应该将Content-type:application / json标头设置为$ .ajax()使用的xhr对象。
$.ajax({
url: "writeJSON.action",
data: data1,
dataType: 'json',
contentType: 'application/json',
The plugin is using $.ajaxSubmit()
, this kind of submission should be eliminated because it doesn't work with json data.
该插件使用$ .ajaxSubmit(),这种提交应该被删除,因为它不适用于json数据。
更多相关文章
- 基于Jquery ui 可复用的酒店 web页面选择入住日期插件
- 如何使用jQuery UI插件使html文本框可拖动和调整大小?
- Web开发者必备的20款超赞jQuery插件
- 使用jQuery的dataTable插件和嵌套的Ajax调用
- 如何将一个div中的a标签放在另一个div的a标签之前
- 关于jQuery获取html标签自定义属性值或data值
- Dreamweaver Cs4 jQuery自动提示插件绿色版
- zTree -- jQuery 树插件 使用小结
- 《JQuery——插件的开发和使用(二)之qTip2 插件的使用》