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数据。

更多相关文章

  1. 基于Jquery ui 可复用的酒店 web页面选择入住日期插件
  2. 如何使用jQuery UI插件使html文本框可拖动和调整大小?
  3. Web开发者必备的20款超赞jQuery插件
  4. 使用jQuery的dataTable插件和嵌套的Ajax调用
  5. 如何将一个div中的a标签放在另一个div的a标签之前
  6. 关于jQuery获取html标签自定义属性值或data值
  7. Dreamweaver Cs4 jQuery自动提示插件绿色版
  8. zTree -- jQuery 树插件 使用小结
  9. 《JQuery——插件的开发和使用(二)之qTip2 插件的使用》

随机推荐

  1. Python - 将值打印到新文件?
  2. 真正最正确的用BAT运行JAVA不显示DOS窗口
  3. Tkinter小部件上的垂直和水平滚动条
  4. 在Python中TypeError: object() takes no
  5. Python_面向对象_单例模式
  6. 用python计算20日均线数值
  7. Python添加默认模块搜索包路径
  8. python的list要打印中文字符
  9. Python——函数 8、可变长参数
  10. 任何人都可以提供更多的pythonic方式来生