在我的母版页中,我有
<head>
<script type="text/javascript">
$(document).ready(function() {
$("#result").click(function() {
$.ajax({type: "POST",url: "ws.aspx/HelloWorld",data: "{}",contentType: "application/json; charset=utf-8",dataType: "json",success: function(msg) {
$("#result").text(msg.d);
}
});
});
</script>
</head>
<body>
<form>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
<div name="result" id="result">long clicky text</div>
</form>
</body>
在我的 ws.aspx 页面中,该页面没有母版页引用,并且是空的,除了
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ws.aspx.vb" Inherits="CRTWebApp.ws" %>
<html>
<head>
</head>
<body>
</body>
在我的 ws.aspx.vb 文件中,它是这样声明的
<System.Web.Services.WebService()> _
Partial Public Class ws
Inherits System.Web.UI.Page
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod(ResponseFormat:=Script.Services.ResponseFormat.Json)> _
Public Shared Function HelloWorld() As String
Return "hello world"
End Function
End Class
在萤火虫中,如果我点击“long clicky text”,就会发生这种情况
POST HelloWorld 404 Object Not Found
ws.aspx 在同一个文件夹中,它吐出的 url 是正确的,我可以浏览该页面(虽然它是空的..)
这是请求和响应
Response Headers
Server Microsoft-IIS/5.1
Date Wed, 15 Sep 2010 21:43:37 GMT
WWW-Authenticate Negotiate NTLM
Connection close
Content-Length 4431
Content-Type text/html
Request Headers
Host localhost
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 (.NET CLR 3.5.30729)
Accept application/json, text/javascript, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/json; charset=utf-8
X-Requested-With XMLHttpRequest
Referer http://localhost/CRTWebApp/SysAdmin/cat.aspx?lang=en
Content-Length 2
Cookie ASP.NET_SessionId=clvadayboyqwilizioi4ks55
Pragma no-cache
Cache-Control no-cache