2

I am trying to call classic ASP function from jQuery ajax but it is giving 404 error. I want to return records inJSON in this javascript code:

$.ajax({
    type: "POST",
    url: "../dbFile.asp/GetAllRecords",
    data: {"Id"="10"},
    error: function(XMLHttpRequest, textStatus, errorThrown){
        alert(textStatus);
    },
    success: function(result){
       alert("success");
    }
});
return false;
});

and my vb script function in asp classic file is

Function GetAllRecords()
    dim cmd, rs
    set cmd=Server.CreateObject("ADODB.Command")
    cmd.ActiveConnection = conn
    cmd.CommandType = 4
    cmd.CommandText = "GetAllRecords"
    set rs=Server.CreateObject("ADODB.Recordset")
    set rs=cmd.Execute()
    set GetAllRecords= rs
    set rs=nothing
    set cmd=nothing
End Function

Please guide, I am stuck here.

1 Answer 1

4

You cannot call a classic ASP page as if you're calling ASP.NET WebMethod. You can call it by passing a parameter in Querystring, e.g.

url: "../dbFile.asp?Action=GetAllRecords",

And in your ASP code do something like

If Request("Action") = "GetAllRecords"
   Response.Write GetAllRecords()
   Response.End
End If

Note: For this to work your GetAllRecords() function need to return actual string with JSON or XML, right now it retruns a Recordset. You need to loop thru recordset, building string in the correct format.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your comprehensive answer. I managed to solve my problem by using aspjson liberary by calling asp page and returning data in form of json.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.