2012-07-18 85 views
0

輸出的 「http://本地主機:6833/Service1.asmx的/的HelloWorld」:問題與jQuery和C#的Web服務從網絡服務,

<string xmlns="http://tempuri.org/"> 
[{"Name":"Pini","Age":"30","ID":"111"},{"Name":"Yaniv","Age":"31","ID":"Cohen"},{"Name":"Yoni","Age":"20","ID":"Biton"}] 
</string> 

HTML代碼:

<html> 
<head> 
<script type="text/javascript" src="jquery-1.7.2.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$.ajax({ 
     type: "POST", 
     url: "Service1.asmx/HelloWorld", 
     data: "{}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function(msg) { 
      alert("Result: " + msg); 
     }, 
     error: function(XMLHttpRequest, textStatus, errorThrown) { 
      alert("Error: " + textStatus); 
    } 
}); 
}); 
</script> 
</head> 
<body> 
</body> 
</html> 

當我在瀏覽器中運行index.html我得到了錯誤警報..試了很多東西,但無法找出什麼缺失..

+0

有什麼errorthrown? – 2012-07-18 11:14:09

+0

唯一錯誤:錯誤。但不知道該功能是如何工作的,所有這個新的 – stianboe 2012-07-18 11:18:58

+0

試試這個提醒(「Error:」+ errorThrown);並告訴我你得到了什麼。 – 2012-07-18 11:20:11

回答

1

你的JSON封裝在一個XML字符串,我想這就是你的問題。

編輯:

檢查this後以獲取更多信息。

+1

是的,我認爲響應應該是普通的舊JSON ... – 2012-07-18 10:57:12

+0

不知道該怎麼做,我嘗試谷歌一些。 – stianboe 2012-07-18 11:17:40

+0

檢查我添加的鏈接。 – randoms 2012-07-18 11:52:55

0

嘗試在您的方法之前添加此項。

[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 

下面

[WebMethod] 
+0

那已經到位,沒有工作。 – stianboe 2012-07-18 11:17:15