2010-09-15 64 views
0

在我的母版页,我在ws.aspx页面,其中有没有母版页引用.NET 2.0 AJAX的jQuery PageMethod的404对象未找到

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

,并且是除空

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

的萤火,如果我对“长clicky文本”点击这个是什么情况

POST HelloWorld 404 Object Not Found 

ws.aspx是在同一文件夹,它吐出来的网址是正确的,我可以浏览到该页面(虽然它是空的。)

这里是请求和响应

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

为什么使用aspx页面方法而不是asmx Web服务? – 2010-09-15 21:57:53

+0

我以前曾尝试使用网络服务,但无法正常工作。我想我在我的web服务中缺少几行,这就是它现在的样子: – pliz22 2010-09-16 14:34:05

+0

Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel Imports system.Web.script Imports System.Web.Script.services _ _ _ <的ToolboxItem(假)>公共类wssw 继承的System.Web .Services.WebService _ Public Function HelloWorld()As String Return“Hello World” End Function End Class – pliz22 2010-09-16 14:34:49

回答

0

相反ASPX网页的创建,你应该建立一个ASMX页。如果您单击解决方案树上的鼠标右键并选择“添加”,“新建项目”,然后选择Web模板列表中的“Web服务”模板(最后一个),您可以将新服务添加到Web应用程序中。

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

+0

我曾试过这个,但我把asmx页放在bin或app_code文件夹中。我按照你的建议再次尝试,并将asmx放在与母版页和其他所有内容相同的虚拟目录中。我很高兴地说它现在可行!尽管我仍然无法将它用作aspx中的pagemethod。 – pliz22 2010-09-16 14:31:11

+0

@ pliz22:我很高兴在这里程序开始工作!使用正确的扩展名对于网页非常重要。它定义了如何处理请求。例如,如果您尝试使用.html,它将不起作用。所以留在ASMX,它会工作。解释为什么太长的评论。对不起。另一个我的答案http://stackoverflow.com/questions/3445859/asmx-web-service-json-javascript-jquery/3446517#3446517可能对你也很有趣。 – Oleg 2010-09-16 15:05:14

0

是否实际的页面没有关闭的HTML标记?

</html> 
+0

yes,it ..对不起。 – pliz22 2010-09-16 14:29:32

1

我不知道为什么你会得到一个404路径以外的错误。您应该考虑使用Web服务。阅读这篇文章:

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

+0

是的,我读了该页面和encosia中的其他链接与jquery调用的更新,使用msg.d,添加数据:“{}”等等等等,但我永远不能得到它的工作。我认为可能在这个网站上缺少步骤。路径是正确的,但是,我认为ws.aspx/HelloWorld不是一个真正的页面,它试图冲浪那里而不是消费Web服务。 – pliz22 2010-09-16 14:33:01