Send JSON object to Struts 2 action by using strut2 jquery plugin tags(使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作)
问题描述
我们可以通过 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().
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 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作
基础教程推荐
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
