Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Javascript

Ajax method not calling server side Controller method

2.50/5 (3 votes)
29 Jan 2016CPOL 7K  
Solution if Ajax method not calling Controller method every time its invoked

Introduction

This might help in firing the Controller method, everytime its invoked via an Ajax call.

Background

My ajax call was not calling the Controller method on the server side, even though it was invoked everytime.

Using the code

With cache:false, i was able to have the Server side controller method fired everytime, the function was invoked from the page. 

C++
var selectedGuid;

can_Edit_Submit_Approve_Order(selectedGuid) //function call in my page

function can_Edit_Submit_Approve_Order(opportunityId) 
    {
       
        $.ajax({
            url: "/Order/Can_Edit_Submit_Approve_Order/?opportunityId=" + opportunityId,
            type: "GET",
            cache: false,
            success: function (result) {
                
                if (result.length > 0)
                {
                    //custom logic to enable / disable releavant buttons here
                }
                else
                {
                    //code for default button disable
                }
            }
        });
    }

Points of Interest

Without cache:false, i did verify that the controller call was being by-passed/ missed due to some reason (not for the first time though but consistently thereafter).

History

License

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