0
以下是服務。使用JQuery調用Restful服務
[WebGet(UriTemplate = "{city}", ResponseFormat=WebMessageFormat.Json)]
string FormatAddress(string city);
public string FormatAddress(string city) { return city; }
這是客戶端。 像這樣的URL調用http://localhost:8210/formataddress/irvine
返回城市名稱,如預期。
像這樣從JQuery調用不會返回成功。
$.ajax({
type: "GET",
url: "http://localhost:8210/formataddress/irvine",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: onError,
success: onSuccess
});
function onSuccess(data, status) {
alert("inside onSuccess");
}
function onError(data, status) {
alert("inside onError");
}
我已經試過路過城市的名字,像這樣的數據:{"city" : "irvine"}
和 其他各種調整到$.ajax
方法參數。
任何想法的如何我可以訪問inside onSuccess
消息顯示?
順便說一句,所有的項目都在同一VS2008解決方案。
請編輯您的文章並使用代碼格式化按鈕。 – 2011-06-16 16:31:22
您是否檢查過響應碼以查看它是否正常? (200,304等)。您是否也看到了請求正文中的內容實際上就像您期望的那樣? – agmcleod 2011-06-16 16:32:01
此外,響應的內容類型是什麼(檢查響應的標題) – ashelvey 2011-06-16 16:38:31