marchemike
marchemike

Reputation: 3277

Ajax request cannot access method on .aspx file

I'm trying to call a method in my .aspx file to call another .aspx file. The file that I am using is inside another folder, and the file I need to access using javascript is outside similar to this structure:

Root Folder:
PageMethods.aspx
    SubFolder/
       Somefile.aspx

Here is my ajax request:

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/PageMethods.aspx/TagtoVehicle",
        data: "{'colIDBigint': '" + IDBigInt + "', 'colTravelReqIDInt': " + TravelReq +
            ", 'colRecordLocatorVarchar': " + RecordLoc + ", 'colSeafarerIdInt': " + SeafarerId + ", 'colOnOff': " + onoff + ", 'colPortAgentVendorIDInt': " + Vehiclevendor + ", 'UserId': " + userId + "}",
        dataType: "json",
        success: function(data) {
        } ,
        error: function(objXMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });

When I run the ajax request it throws an error 500 (Internal Server Error).

Why is the request not going thru, even if inside my PageMethod.aspx.cs is this:

[WebMethod]
        public static string TagtoVehicle(Int32 colIDBigint, Int32 colTravelReqIDInt, string colRecordLocatorVarchar, Int32 colSeafarerIdInt, string colOnOff, Int32 colPortAgentVendorIDInt,string UserId)
        {

}

What is triggering the error 500?

Upvotes: 0

Views: 816

Answers (3)

Phong Nguyen
Phong Nguyen

Reputation: 277

Error: 500 cause by your data format: make it simply, try this:

data:{"variable":data, "variable1":data1,...}

Jquery latest version support this kind, you can give a try! As my experience, this way is better. Good luck

Upvotes: 0

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14604

You are missign quotes around values.Just like you have encoded value of colIDBigint do same for all of the remaning

data: "{'colIDBigint': '" + IDBigInt + "', 'colTravelReqIDInt': '" + TravelReq +
        "', 'colRecordLocatorVarchar': '" + RecordLoc + "', 'colSeafarerIdInt': '" + SeafarerId + "', 'colOnOff': '" + onoff + "', 'colPortAgentVendorIDInt': '" + Vehiclevendor + "', 'UserId': '" + userId + "'}",

Better is that you stringify the data like this

JSON.stringify({colIDBigint:IDBigInt,colTravelReqIDInt:TravelReq})

and like that add other values in data.

Upvotes: 1

4b0
4b0

Reputation: 22323

Use full url:

url: '<%=ResolveClientUrl("~/PageMethods.aspx/TagtoVehicle")%>',

~ means that the path will start at the root of the site.

Upvotes: 0

Related Questions