【发布时间】:2010-01-08 13:53:46
【问题描述】:
好的,所以我创建了一个测试项目,只是为了验证 jQuery AJAX 是否可以与 asp.net 服务一起使用,并且没有问题。我使用了在 VS Studio 中创建的默认 HelloWorld 服务。我像这样通过 jQuery 调用服务:
在 Default.aspx 中:
<script language="javascript" type="text/javascript">
$(document).ready(function() {
//test web service
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "TestService.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function(msg) { alert(msg);},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
}
});
});
</script>
在 TestService.asmx 中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebServiceTestWitJQuery
{
/// <summary>
/// Summary description for TestService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class TestService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
然后我继续并完全按照我的项目中的内容复制了所有内容,但它不起作用。我收到 500 服务器错误。
我验证了以下内容:
- web.configs 相同
- 页面相同
- 服务类相同
- jquery ajax 调用相同
- 我可以导航到http://localhost:3272/TestService.asmx?op=HelloWorld 并且网络服务工作正常。
还有什么?
【问题讨论】: