问题描述
前台的 静态json数据var resContactInfos1 = [{ metadataId: '001',orgCode:'001',orgName: 'zhangsan', address: '20', email: 'shanghai' }, { metadataId: '002', orgCode: '002', orgName: 'beijing', address: '21', email: 'beijing' } ]; ajax 请求 var data1={resContactInfo:resContactInfos1};$.ajax({ url: "rc/resourceCatalogManagerAction!saveResource.action", //后台处理的地址 type: "POST", contentType: "application/json", data: JSON.stringify(data1), success:function(){ alert("success"); }}); 后台actionprivate list<ResContactInfo>resContactInfo;后台有个resContactInfo属性 它的get set方法也写了 ResContactInfo这个类的属性为 metadataId 、orgCode等 同上面的json对象中的5个属性 问题 :我看到浏览器发的请求 感觉是没有问题的 但是后台显示接不到值 求解???
解决方案
可参考我的博客:http://quarterlifeforjava.iteye.com/blog/2024336希望能帮到你
解决方案二:
请问,后台你是如何接收的?
解决方案三:
可能是你的格式错了:如:你参考的代码中初始数据 后面的值是双引号 而你的是单引号var persons = [{ id: "001", name: "zhangsan", age: "20", gender: true, city: "shanghai" }, { id: "002", name: "lisi", age: "21", gender: false, city: "beijing" } ];var resContactInfos1 = [{ metadataId: '001',orgCode:'001',orgName: 'zhangsan', address: '20', email: 'shanghai' }, { metadataId: '002', orgCode: '002', orgName: 'beijing', address: '21', email: 'beijing' } ];
解决方案四:
在ajax中添加dataType: "json"估计就可以了。
解决方案五:
var data1={resContactInfo:resContactInfos1};改为var data1={"resContactInfo":resContactInfos1};
解决方案六:
$.ajax({ url: "rc/resourceCatalogManagerAction!saveResource.action", //后台处理的地址 type: "POST", contentType: "application/x-www-form-urlencod", data: JSON.stringify(data1), success:function(){ alert("success"); }});把contentType改一下就可以了
解决方案七:
能把请求头信息截图看一下么?我怀疑是var data1={resContactInfo:resContactInfos1};这一句多余了
解决方案八:
好像ajax请求少个datatype吧var markers = [{ "position": "128.3657142857143", "markerPosition": "7" }, { "position": "235.1944023323615", "markerPosition": "19" }, { "position": "42.5978231292517", "markerPosition": "-3" }];$.ajax({ type: "POST", url: "/webservices/PodcastService.asmx/CreateMarkers", data: JSON.stringify({ Markers: markers }), contentType: "application/json; charset=utf-8", dataType: "json", success: function(data){alert(data);}, failure: function(errMsg) { alert(errMsg); }});