Click here to Skip to main content
15,902,922 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one user control.
In that, I am using Ajax post method, but when I am accessing the same user control in my aspx page, it don't get URL parameter and gives me error 'undefined'.
My code is as below:
JavaScript
function GetRecords(index) {
    //alert(index);

    pageIndex = index;

    $("#loader").show();
    $.ajax({
        type: "POST",
        url: "Customer.ascx/GetCustomers",
        data: '{pageIndex: ' + pageIndex + '}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function (response) {
            alert(response.d);
        },
        error: function (response) {
            alert(response.d);
        }
    });
} 

C#
[WebMethod]
public static string GetCustomers(int pageIndex)
{       
    return GetCustomersData(min, max, pageIndex).GetXml();
}
Posted
v2
Comments
Check if the URL Customer.ascx/GetCustomers is correct or not?

1 solution

Hi,

This ajax call that you are making, is it existing on the ascx control or some separate file.

one thing i recognized is that, the path that you are giving here, should be complete path from

root directory or use a '~' operator. so that there will be no problem with the path.

The thing with the paths is when they were placed in the control and this control is referenced

in an other page. the path is not tracked properly.

so, you can try one of the two approaches (if the path is a problem)

use :

1) var originalPath="<your_site_url_>+ <webservices_directory>"

now you can call like" Url:originalPath+"<webmethod_needed>"


2) try to put a '~' operator. and set path to webservices directory.

Hope this helps.

you should always try to implement the ajax calls in a separate file so that you can debug

and see y they fail.

Happy coding..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900