.net 2.0 ajax jquery pagemethod 404 未找到对象

发布于 2024-09-19 11:39:13 字数 2228 浏览 9 评论 0原文

在我的母版页中,我

<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>

它在 firebug 中是这样声明的

<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

在我的 ws.aspx.vb 文件中,如果我单击“长点击文本”, “这就是发生的情况

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

in my master page, i have

<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>

in my ws.aspx page, which has no master page references, and is empty except for

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ws.aspx.vb" Inherits="CRTWebApp.ws" %>

<html>
<head>
</head>
<body>
</body>

in my ws.aspx.vb file it is declared like this

<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

in firebug, if i click on "long clicky text" this is what happens

POST HelloWorld 404 Object Not Found

ws.aspx is in the same folder, the url it spits out is the correct one, i can surf to that page (though it is empty..)

here is request and response

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心是晴朗的。 2024-09-26 11:39:13

除了路径错误之外,我不确定为什么会收到 404。您应该考虑使用网络服务。阅读这篇文章:

http:// /encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/

I'm not sure why you would be getting a 404 other than the path being wrong. You should look into using a web service. Read this article:

http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/

江城子 2024-09-26 11:39:13

您应该创建一个 ASMX 页面,而不是创建 ASPX 网页。如果单击解决方案树鼠标右键并选择“添加”、“新项目”,然后在 Web 模板列表中选择“Web 服务”模板(最后一个),则可以向 Web 应用程序添加新服务。

如果您使用旧版本的 Visual Studio,请参阅 http://support.microsoft.com/kb/301273 或 http://www.vbdotnetheaven.com/UploadFile/mmehta/SimpleWebService04262005065102AM以 /SimpleWebService.aspx 为例。

Instead of creating of ASPX web page you should create a ASMX page. You can add new service to your Web Application if you click on the solution tree right mouse button and choose "Add", "New Item" and then choose "Web Service" template (the last one) on the list of Web Templates.

If you use old version of Visual Studio see http://support.microsoft.com/kb/301273 or http://www.vbdotnetheaven.com/UploadFile/mmehta/SimpleWebService04262005065102AM/SimpleWebService.aspx as an example.

凉风有信 2024-09-26 11:39:13

实际页面没有结束 HTML 标记吗?

</html>

Does the actual page NOT have a closing HTML tag?

</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文