我嘗試使用JQuery從Web服務進行簡單調用。 它給了我「500內部服務器錯誤」。 這裏是我的腳本:500內部服務器錯誤ASP.NET
<script type="text/javascript">
$(document).ready(function() {
$("#sayHelloButton").click(function(event) {
$.ajax({
type: "POST",
url: "dummyWebsevice.asmx/HelloToYou",
data: "{'name': '" + $('#name').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
這裏是我在網絡服務端代碼:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class dummyWebservice : System.Web.Services.WebService
{
[WebMethod()]
public string HelloToYou(string name)
{
return "Hello and welcome, " + name;
}
[WebMethod()]
public string sayHello()
{
return "Hi!";
}
}
我很抱歉,如果我的問題是多餘的,但我不能似乎找到了我的錯誤,我對此仍然很陌生。 預先感謝您。
我從這個頁面之後的例子: http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx
當您在Web服務方法中放置斷點時,您會得到什麼?它是否像你期望的那樣觸及了這個方法?傳入參數中有什麼? – 2011-05-06 06:18:26