我无法从我的 JQuery 调用中进入我的 Search WebMethod。也许有人可以帮助我指出正确的方向。
我还将所有内容打包成一个 zip 文件,以防有人想仔细查看。
http://www.filedropper.com/jsonexample
谢谢瑞恩
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JSON Example</title>
<script type="text/javascript" language="JavaScript" src="jquery-1.3.1.min.js"></script>
<script type="text/javascript" language="javascript">
function Search() {
var search = $("#searchbox").val();
var options = {
type: "POST",
url: "Default.aspx/Search",
data: "{text:" + search + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert('Success!');
}
};
$.ajax(options);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="searchbox" size="40" />
<a href="#" onclick="Search()" id="goSearch">Search</a>
<br />
<div id="Load" />
</form>
</body>
</html>
这是 default.aspx 背后的代码
Imports System.Data
Imports System.Web.Services
Imports System.Web.Script.Serialization
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function Search(ByVal text As String) As IEnumerable
Return "test"
End Function
End Class