ajax java 数组字符串_如何在jQuery ajax调用中使用数组字符串?

通过使用jQuery,我试图在后端保存我的字符串数组,以下是我的方法。

1.使用jQuery ajax发送数组。var tagTexts = $(ul li.select2-selection__choice")

.toArray()

.map(function(i){

return i.innerText;

});tagTexts = tagTexts.join(',');$.ajax({

type: 'POST' ,

url: '/tag/tagList',

dataType: 'json',

data: {

tagTexts: tagTexts    },

error: function(err) {

console.log(err);

},

success: function(response) {

//Process Response

}});

2.在后端,检索如下:@ResponseBody@RequestMapping(value = "/tag/tagList", method = RequestMethod.POST)public String saveTagList(HttpServletRequest request,

@RequestParam(value = "tagTexts", required = false)ListtagTexts) {

System.out.println(tagTexts);

String response = tagService.saveTags(tagTexts);

return response;}

a)使用数组连接方法

以下是捕获的字符串数组:["Drone", "Richard Feynman, PHD", "Yatch"]

使用数组连接方法后,它会更改如下:Drone,Richard Feynman, PHD,Yatch

在java执行(后端)中,它显示如下:[Drone, Richard Feynman, PHD, Yatch]

b)使用JSON.stringify方法

使用JSON.stringify方法后,捕获的数组显示如下:["Drone", "Richard feynman, PHD", "Yatch"]

这在js级别看起来很好但是这整行被认为是一个字符串,它在后端显示如下:[["Drone", "Richard feynman, PHD", "Yatch"]].

我期待我的代码工作如下:捕获的原始数据元素中的逗号字符不应拆分。

整个数组不应该在后端显示为字符串。

有没有更好的方法来实现这一目标?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值