Question

I'm having trouble getting an AJAX call to work, The fail error is the common 404 which means that the call cant find the file/function i wish to call. The problem is even when i use an absolute path in the call it still 404's on me. I can physically inspect the file on the server and even using the same path access an image or .txt file in the same directory through the web.

$.ajax({
        type: "post",
        url: "http://10.xx.xx.xx/Scripts/Core.aspx.vb/GetData",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{"selCourse":"'+crsName+'"}',
        success: function(result) {
            ProcessServerLsnList(result.d);
        },
        error: function (xhr, status, error) {
            AjaxErrorAlert(error);
        }       
    });

As i'm forced to code this from Dreamweaver as a run time compiled codebehind.(Don't ask...) Is there something simple i'm missing that i should check, be it in the asp or iis config on the server or the web.config.

default.aspx Header

<%@ Page Language="vb" AutoEventWireup="true"  Src="Scripts/Core.aspx.vb" Inherits="CoreFunctionality"%>
<!DOCTYPE>
<html>
<head runat="server">

Core.aspx.vb

Imports System.IO
Imports System.Web.Services.WebService

public partial Class CoreFunctionality
    Inherits System.Web.UI.Page
        Public Function GetData(ByVal strData As String) As String
            return String.Format("It's blank Jim.", strData )
    End Function    
End Class

background Info on what i need to implement: User clicks on an item it performs multiple javascript actions then without refreshing, the page retrieves data from the server and performs several more javascript actions, before reacting to the users request.

Was it helpful?

Solution

Now i understand that this might not be the most efficient method, or necessarily the industry standard and correct method, but it works for my small use edge case where data security is not much of a concern.

As it turn's out i wasn't too far off the mark but as makeMoney2010 mentioned i couldn't call the aspx.vb file directly so i attached it instead to an empty page and called that page to act as a background processor of information. (Most likely incorrect terminology)

The below code should guide anyone else who doesn't know ajax and vb asp.net but needs for some or other reason that defies the norm to be able to call functions on the server from javascript and return some data from a run time compiled codebehind file.

Core.aspx (Background Processor)

<%@ Page Language="vb" AutoEventWireup="true"  Src="Core.aspx.vb" Inherits="CoreFunctionality"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Processing Data...</title>
</head>

<body>
Processing Data, Please Wait...
</body>
</html>

Core.aspx.vb (The serverside script)

    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Web.Script.Services

public partial Class CoreFunctionality
    Inherits System.Web.UI.Page

        <WebMethod()> _
        Public Shared Function GetLessonList(ByVal crsName As String) As String
        If crsName = "" Then
            return String.Format("It's blank Jim.", crsName)
        Else
            return String.Format("Oodles of list data here!!!", crsName)
        End If
    End Function


End Class

ClientSide.js (Client side javascript)

function GetSegListFromServer(strData){
    $.ajax({
        type: "post",
        url: "Scripts/Core.aspx/DoSomenthig",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        //data: '{"selCourse":"'+crsName+'"}',
        data: '{"lsnName":"'+lsnName+'", "crsName":"'+crsName+'"}',
        success: function(result){
            ProcessReturnedData(result.d);
        },
        error: function (xhr, status, error) {
            AjaxErrorAlert(error);
        }       
    });
}

function ProcessReturnedData(){
    alert("@TODO:");
}

//Generic Ajax error handler
function AjaxErrorAlert(error){
    alert("AJAX Error: "+error);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top