views:

71

answers:

3

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

Does the actual page NOT have a closing HTML tag?

</html>
Mark Schultheiss
yes, it does.. sorry.
pliz22
+1  A: 

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/

fehays
yes, i read that page and the other links within encosia with the updates to the jquery call, using msg.d, adding a data:"{}" thing etc. etc. but i could never get it to work. i think there may be steps missing on this site. the path was right, but, i think ws.aspx/HelloWorld is not a real page and it was trying to surf there instead of consume the webservice.
pliz22
A: 

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.

Oleg
i had tried this, but i put the asmx page in a bin or app_code folder. i tried it again following your suggestion and put the asmx in the same virtual directory as the master page and everything else. i'm glad to say it works now! although i still can't get it to work as a pagemethod in an aspx.
pliz22
@pliz22: I am glad to here that the program start working! Usage of correct extension is very important for a web page. It define which how the request will be processed. For example if you'll try to use .html it will be not work. So just stay by ASMX and it will work. The explanation why is too long for a comment. Sorry.Another my answer http://stackoverflow.com/questions/3445859/asmx-web-service-json-javascript-jquery/3446517#3446517 could be also interesting for you.
Oleg