代碼如下 |
複製代碼 |
$.post('<%=this.AppPath %>DataService/InventoryUIService.svc/Rename', ///location.protocol + "//" + location.host + location.pathname + "/Rename", odata, function (result) { $dialogProcessing.dialog("close"); if (result.Success) { alert("Success"); } else { var msg = "Your submit fauiler, Detail message is:" + result.ErrorMessage; window.alert(msg); } }, "json"); $.ajax({ url: '<%=this.AppPath %>DataService/InventoryUIService.svc/Rename', type: 'POST', contentType: 'application/json', dataType: 'json', data: odata, success: function (result) { if (result.Success) { alert("Success"); } else { var msg = "Your submit fauiler, Detail message is:" + result.ErrorMessage; window.alert(msg); } }, error: function (jqXHR, textStatus, errorThrown) { var msg = "Your submit throw a error, rnError message is:" + $(jqXHR.responseText).text(); window.alert(msg); } });
|
$.post是用來提交forms的,而要跟wcf ajax service訪問,還必須得用$.ajax來指定Content-Type
You can't send application/json directly -- it has to be a parameter of a GET/POST request.
So something like
代碼如下 |
複製代碼 |
$.post(url, {json: "...json..."}, function()); |