我有以下,但它不工作,我在某个地方读取它的工作原理,但我似乎无法让它工作..它的错误…我做错了什么?
如果我传递这样的数据 – 它的工作 – 所以我知道我的服务正在工作
//THIS WORKS data: "{one : 'test',two: 'test2' }" // BUT SETTING UP OBJECT doesn't work.. var saveData = {}; saveData.one = "test"; saveData.two = "tes2"; $.ajax({ type: "POST",url: "MyService.aspx/GetDate",data: saveData,contentType: "application/json; charset=utf-8",dataType: "json",success: function(msg) { alert(msg.d); },error: function(msg) { alert('error'); } });
解决方法
我相信代码将在对象上调用.value或.toString(),然后通过线.你想传递JSON.
所以,包括json javascript库
然后通过…
var saveData = {}; saveData.one = "test"; saveData.two = "tes2"; $.ajax({ type: "POST",data: JSON.stringify(saveData),// NOTE CHANGE HERE contentType: "application/json; charset=utf-8",success: function(msg) { alert(msg.d); },error: function(msg) { alert('error'); } });