默认使用jquery.param 序列化数组时 参数名称会额外生成 %5B%5d [] 这样的内容
解决办法 :
添加第二个参数:true
JSON.stringify(newsId)()--->ajax使用成功,$post 防止并没有成功.
实例1:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="jquery.min.js"></script> </head> <body> </body> <script> //第一种参数形式 var obj = { areaName: "abc", // 标题 title: "def", sourceTypes:[1,2,3], }; console.log("=>",jQuery.param(obj,true)); console.log("===>",jQuery.param(obj)); </script> </html>
结果:
=>, areaName=abc&title=def&sourceTypes=1&sourceTypes=2&sourceTypes=3
===>, areaName=abc&title=def&sourceTypes%5B%5D=1&sourceTypes%5B%5D=2&sourceTypes%5B%5D=3
实例二:
$.ajax({ url: '/user', contentType: "text/html;charset=UTF-8", type: "POST", dataType: 'json', data: JSON.stringify(newsId), success: function (res) { tableIns.reload(); layer.close(index); top.layer.msg(res.msg); }, error :function () { tableIns.reload(); layer.close(index); top.layer.msg("提交失败!"); } });
还没有评论,来说两句吧...