Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery $.get call to method in Controller

I have a .csHtml page. The page is populated by calling a method in the contoller using Jquery $.get. The method in the controller makes a database call and returns a partial view. The partial view is rendered inside a DIV tag.

The data is being displayed real time. Now when I hit ctrl + f5, the page refreshes, but it still shows the same data. I put a breakpoint in the controller method and realized that the method in controller is not being called.

The first time the method is being called when I hit F5 and run in Visual Studio. The second time when I refresh the data is not being refreshed.

If I have to see any changes being displayed in the database, I need to restart the visual studio.

Any clue on what could be happenning?? Below is the snippet of code.

// Our onReady actions;
$(document).ready(function () {
    $('#RateTab').click(function () {
        getRates();
    });
});

function getRates() {
    var URL = "home/Rates";

    $.get(URL, function (data) {
        $('#loading').hide();
        $("#rates").html(data);

        //Initialize();
    });
}

Any ideas and suggestions on what could be happenning ??

like image 673
DotNetUser Avatar asked Oct 10 '22 05:10

DotNetUser


1 Answers

I think it's a cache that is enabled. You can control cache by using the $.ajax method. Try to rewrite it like that :

$.ajax({
   url : URL,
   type : 'GET',
   cache : false,
   success : function (data) { 
            $('#loading').hide(); 
            $("#rates").html(data);}
});

Hope it helps.

like image 134
Tomasz Jaskuλa Avatar answered Oct 13 '22 12:10

Tomasz Jaskuλa