广告
淘宝内部优惠券
当前位置: 开发异常方案库» Web 开发 » ajax如何传一个string到webservice,提示web服务调用无效,参数“”缺少值,请问以下报错如何处理?谢谢

ajax如何传一个string到webservice,提示web服务调用无效,参数“”缺少值,请问以下报错如何处理?谢谢

开发异常方案库  收集整理于:2020-05-09 10:48:00  浏览:66次
$("#btn1").click(function () {
				var jsonObj = {"account": "value1","contant": "value2""Detail": [{"product": "value3","model": "value4","QTY": 1}]}
;
				var jsonStr = JSON.stringify(jsonObj);				
				//alert(jsonStr);
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
					async: false,
					dataType: "json",
                    url: "http://localhost:8078/data.asmx/HelloWorld",
                    data: jsonStr,
                    success: function (data) {
                      alert(data.d);
                  	},
                     error: function (data) {
                     alert($.parseJSON(data.responseText).Message);},
                });
            });
[WebMethod]
        public string HelloWorld(string jsonStr)
        {
            return "Hello " + jsonStr;
        }

------网友观点--------------------
jsonObj = {"account": "value1","contant": "value2""Detail": [{"product": "value3","model": "value4","QTY": 1}]} 这块写错了 json格式本身写的有问题

------网友观点--------------------
引用 1 楼 usecf 的回复:
jsonObj = {"account": "value1","contant": "value2""Detail": [{"product": "value3","model": "value4","QTY": 1}]} 这块写错了 json格式本身写的有问题
谢谢检查,我改完之后,还是这样的报错。

------网友观点--------------------
把你改过的jsonObj发出来看看

------网友观点--------------------
引用 3 楼 usecf 的回复:
把你改过的jsonObj发出来看看
 $("#btn1").click(function () { var jsonObj = {"OPNAME": "testname","APPLYNO": "AbbrOP01","OPACID": 3424,"OPAMT": 1000,"OPCURR": "CNY","OPCREA": "LJY","OPOWNR": "RFS","OPNEED": "XUQIU","OPCPTI": "MINGXE","OPCOMP": "LUOSHI","Shipto": "10001","Detail": [{"OUPROD": "WWREWS","OUMODE": "WERWED","OUQTY": 1,"OUEXPP": 1,"OUMINQ": 1}]}; //var jsonStr = JSON.stringify(jsonObj); //alert(jsonStr);                 $.ajax({                     type: "POST",                     contentType: "application/json; charset=utf-8", async: false, dataType: "json",                     url: "http://localhost:8078/data.asmx/HelloWorld",                     //data:{"jsonStr":"{\"account\": \"value1\",\"contant\": \"value2\"}"}, data:???,                     success: function (data) {                       alert(data.d);                    },                      error: function (data) {                      alert($.parseJSON(data.responseText).Message);},                 });             });

------网友观点--------------------
引用 4 楼 qq_16630463 的回复:
Quote: 引用 3 楼 usecf 的回复:
把你改过的jsonObj发出来看看
 $("#btn1").click(function () {
				var jsonObj = {"OPNAME": "testname","APPLYNO": "AbbrOP01","OPACID": 3424,"OPAMT": 1000,"OPCURR": "CNY","OPCREA": "LJY","OPOWNR": "RFS","OPNEED": "XUQIU","OPCPTI": "MINGXE","OPCOMP": "LUOSHI","Shipto": "10001","Detail": [{"OUPROD": "WWREWS","OUMODE": "WERWED","OUQTY": 1,"OUEXPP": 1,"OUMINQ": 1}]};
				//var jsonStr = JSON.stringify(jsonObj);				
				//alert(jsonStr);
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
					async: false,
					dataType: "json",
                    url: "http://localhost:8078/data.asmx/HelloWorld",
                    //data:{"jsonStr":"{\"account\": \"value1\",\"contant\": \"value2\"}"},
					data:JSON.stringify({"jsonStr":JSON.stringify(jsonObj)}),
                    success: function (data) {
                      alert(data.d);
                  	},
                     error: function (data) {
                     alert($.parseJSON(data.responseText).Message);},
                });
            });

------网友观点--------------------
你要给 jsonObj 变量的字符串加引号的 jsonObj  ='{"OPNAME": "testname","APPLYNO": "AbbrOP01","OPACID": 3424,"OPAMT": 1000,"OPCURR": "CNY","OPCREA": "LJY","OPOWNR": "RFS","OPNEED": "XUQIU","OPCPTI": "MINGXE","OPCOMP": "LUOSHI","Shipto": "10001","Detail": [{"OUPROD": "WWREWS","OUMODE": "WERWED","OUQTY": 1,"OUEXPP": 1,"OUMINQ": 1}]}' 然后你要传递json对象 就用下面这个 var jsonStr = JSON.stringify(jsonObj);
发布此文章仅为传递网友分享,不代表本站观点,若侵权请联系我们删除,本站将不对此承担任何责任。
软件开发 程序错误 异常 ybaby.netCopyright © 2020-2026  ybaby 版权所有  桂ICP备17004385号-2 网站地图