Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Experts,

I have a question regarding the usage of ajax post call while using the MapPageRoute code in global.asax .

I'll show you some example that i have used.

In the Global.asax File Code looks like this.

protected void Application_Start(object sender, EventArgs e)
       {

           RouteTable.Routes.MapPageRoute("ICPDR", "InitialClaimReport", "~/Accounts/PC/Initial_Claim_Report.aspx");

       }




And in the Js File Look like this.


$.ajax({
       "dataType": 'json',
       "contentType": "application/json; charset=utf-8",
       "type": "POST",
       "url": "InitialClaimReport/populate_User/",
       "data": {},
       "success":
           function (json) {

               $('#ddl_User').find('option').remove();
               $("#ddl_User").append('<option value="0"></option>');
               $.each(JSON.parse(json.d).list, function (key, val) {

                   $("#ddl_User").append('<option value="' + val.ID + '">' + val.User+ '</option>');


               });

           },
       "error": function (xhr, status, p3, p4) {
           var err = "Error " + " " + status + " " + p3 + " " + p4;
           if (xhr.responseText && xhr.responseText[0] == "{")
               err = JSON.parse(xhr.responseText).message;
           alert(err);
       }
   });



And in the Code behind


[WebMethod(EnableSession = true)]       
        public static string populate_User()
        {

            try
            {
                BLL_Users objusr_BLL = new BLL_Users();                
                return objpractice_BLL.Fetch_UserList();

            }
            catch (Exception ex)
            {
                
                throw;
            }



        }



I have used the above code but My Ajax call is not woking.

Can you please help me to the use of the ajax call while using the routing in asp.net (Not MVC)

Thanks
Dileep..

What I have tried:

I have tried the above code and it is not working. please advise me what is wrong.
When i tried i got the error below...


POST http://localhost:7777/InitialClaimPendingDetailReport/populate_practice 404 (Not Found)
Posted
Updated 6-Sep-17 15:41pm
v3
Comments
Member 10398773 6-Sep-17 9:15am    
What error are you getting on your console?Open mozzila or chrome and check the error which is displayed on the console.
dilzz 6-Sep-17 9:45am    
I got the error below..

POST http://localhost:7777/InitialClaimReport/populate_User 404 (Not Found)
Member 10398773 6-Sep-17 11:41am    
You are accessing it via GET and thats why you are getting 404 .Decorate you method as below with HttpPost attribute

[HttpPost]
[WebMethod(EnableSession = true)]
public static string populate_User()
{

try
{
BLL_Users objusr_BLL = new BLL_Users();
return objpractice_BLL.Fetch_UserList();

}
catch (Exception ex)
{

throw;
}



}

1 solution

In markup view/fontend page, Have you put every your $.ajax inside $(document).ready(function(){
$.ajax({});
}) for automatic calling or event binding to control that said.

one more things i check out this is mistakes
 
url: "InitialClaimReport/populate_User",       

Do not put "" (double quotes) to enclosed 'url' for method naming convention in ajax calling, and there should be not "/" after "populate_User"


- Do not use "static" when you calling ajax from fontend page/markup view, it will not work from my experience. Better bundles these coding in SVC file to work.

[WebMethod]
[WebInvoke(Method= "POST", ResponseFormat = WebMessageFormat.Json)]
public string populate_User()
        {
 
            try
            {
                BLL_Users objusr_BLL = new BLL_Users();                
                return objpractice_BLL.Fetch_UserList();
 
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }
 
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