我们可以通过 json
拦截器将 JSON 发送到 Struts2 操作。 http://tech.learnerandtutor.com/send-json-object-to-struts-2-action-by-jquery-ajax/ 有很好的样本.
json
拦截器要求请求内容类型
为application/json
或application/json-rpc
当我们直接使用 Ajax 时可以这样设置:
$.ajax({
url: "writeJSON.action",
data: data1,
dataType: 'json',
contentType: 'application/json',
但是我们正在使用 struts 2 jquery 插件标签(sj:a
和 sj:submit
...)来为我们管理 ajax 调用。
有什么方法可以让我们用这些标签设置contentType
。
我没有找到此标签属性。
如果没有实现还有其他方法可以设置吗
最佳答案
您应该将 Content-type: application/json
header 设置为 $.ajax()
使用的 xhr 对象。
$.ajax({
url: "writeJSON.action",
data: data1,
dataType: 'json',
contentType: 'application/json',
该插件使用$.ajaxSubmit()
,这种提交应该被消除,因为它不适用于 json 数据。
关于jquery - 使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39750113/