這是我的WCF Web服務WCF REST服務郵政法JSON格式
[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "json2")]
StringMessageJson AddEmployee(EmployeeJson emp);
代碼,這是我在服務
public StringMessageJson AddEmployee(EmployeeJson emp)
{
}
在這裏,我的CS文件代碼我正在通過jquery ajax調用webservice方法:
$('document').ready(function()
{
var emp =
{
ID: '',
EmpName: 'Sk',
EmpID: 'A004',
Username: '[email protected]',
Password: 'Aaa',
Address: 'Sec-001',
PhoneNumber: '09',
MobileNumber: '535345345',
EmpTypeID: '2',
EmpTypeValue: ''
};
var datatosend='{"emp":' + JSON.stringify(emp) + '}';
$.ajax(
{
type: "POST",
url: "http://localhost:6943/EmsRestApi.svc/json2",
data: datatosend,
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function (resp)
{
Console.log(resp);
alert("Message\n'" + resp.Message + "'");
},
error: function (e)
{
//console.log(e);
alert(e);
}
});
$.support.cors = true;
});
並運行此之後,我的Chrome控制檯上收到錯誤消息: -
無法加載資源:服務器與405狀態響應(不允許的方法)
請幫我擺脫解決這個問題。
查看相關答案(http://stackoverflow.com/a/14122895/1810429)FWIW。 – J0e3gan 2013-05-09 07:11:30
當我通過谷歌瀏覽器中的開發人員工具進行檢查時,它顯示** GET **請求正在發送而不是Post。 – Sonu 2013-05-09 07:27:13