我试图使用ajax调用web服务,即时获取内部500错误。你能告诉我不确定我做错了什么,我可以毫无问题地调用web方法。
JQUERY AJAX CALL
<script type="text/javascript">
function LoginVailid() {
$.ajax({
url: "http://localhost:49301/AppService.asmx/LoggonAuthentication",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "jsonp",
jsonp: "callback",
crossDomain: true,
success: function (json) {
alert(json.d);
},
error: function () {
alert("Hit error fn!");
}
});
}
</script>
WEBSERVICE METHOD
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string LoggonAuthentication()
{
return "Hello World";
}
}
答案 0 :(得分:0)
试试此代码
[WebMethod]
[ScriptMethod(UseHttpGet = true, XmlSerializeString=false, ResponseFormat = ResponseFormat.Json)]
public string LoggonAuthentication(string callback)
{
return callback + "({message: 'Hello World'})";
}
此article和this SO question可以提供帮助