我正在嘗試設置一個簡單的JQuery示例,以使AJAX調用.NET Web服務。使用下面的例子下面我理解的只是在結果,而不是任何有意義的消息說0 AJAX錯誤:ASP .NET AJAX和JQuery
JavaScript調用
function QSHelloWorld() {
var options = {
type: "POST",
url: "http://localhost:1087/QueryService.asmx/HelloWorld",
data: "{}",
contentType: "application/json",
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
};
$.ajax(options);
}
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert("Error: " + result.status + " " + result.statusText);
}
ASP .NET Web網頁
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jQueryTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript" type="text/javascript" src="js/jquery-1.3.2-vsdoc2.js" />
<script language="javascript" type="text/javascript" src="js/qsAJAX.js" />
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="formMain" runat="server">
<div>
<script type="text/javascript">
QSHelloWorld();
</script>
</div>
</form>
</body>
</html>
ASP .NET WebService
using System.Web.Script.Services;
using System.Web.Services;
namespace QueryService
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class QueryService : WebService
{
[WebMethod]
[ScriptMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
當我打電話給QSHelloWorld時,我得到一個messa gebox說錯誤:0沒有進一步的信息。
我目前正在使用Windows 7運行這個例子,除了.NET Framework 3.5 SP1之外,我是否需要安裝任何特別的東西才能使它正常運行?
感謝,
Daven
其實這就是我過去曾經是這個例子中的一個頁面。 – 2009-11-23 21:16:40