使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作

编程入门 行业动态 更新时间:2024-10-28 08:21:06
本文介绍了使用 strut2 jquery 插件标签将 JSON 对象发送到 Struts 2 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以通过 json 拦截器将 JSON 发送到 Struts2 动作.http:///tech.learnerandtutor/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/send-json-object-to-struts-2-action-by-jquery-ajax/.

json 拦截器要求请求 content typeapplication/jsonapplication/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:asj: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 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-19 01:00:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/625877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   插件   对象   标签   操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!