我收到“内部服务器错误”,试图从json调用Web服务方法。
这是WebService代码:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService1
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
调用页面的标记和脚本如下:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>WebForm1</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script >
$(document).ready(function ()
{
// Add the page method call as an onclick handler for the div.
$("#Result").click(function ()
{
$.ajax({
type: "POST",
url: "WebService1.asmx/HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(xhr, status, error)
{
$("#Result").html("xhr: " + xhr.text + "</br>Status: " + status + "</br>Error: " + error);
},
success: function (data)
{
$("#Result").html(data.d);
}
});
});
});
</script>
</head>
<body>
<div id="Result">Click here ...</div><br/>
<input id="KenID" />
</body>
</html>
我不确定要检查什么才能使这个简单的应用程序正常工作。
会欣赏一些提示。
亚切克