pleongomez
pleongomez

Reputation: 9

jquery and page reload

I have this code in my asp.net webform, I call a webmethod to load data from database:

function Inicializar() {
   $("#wait").show();

    $.ajax({ type: "POST",
        url: "index.aspx/Iniciar",
        data: JSON.stringify({}),
        contentType: 'application/json; charset=utf-8',
        dataType: "json",
        success: function (response) {

            $("#wait").hide();

            var result = response.d;
            cargardatos(result );
        }
    });

}

I call this function in ready event:

$(document).ready(function () {
 Inicializar();
});

the first time it works, the problem is that when I press F5 and reload the page data is not loaded, and if I press back working again.

I do not know if I'm doing something wrong.

Sorry for my English..Xd

Thank you. Greetings!

Upvotes: 0

Views: 70

Answers (2)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167162

JavaScript is CaSe SenSitIve. So change your code to:

$(document).ready(function () {
   Inicializar();
});

But this way, it doesn't even work on the first time. And do check what is wrong with your output using the Network or Console.

Disable Caching if Needed

$.ajax({ type: "POST",
    url      : "index.aspx/Iniciar",
    cache    : false,
    datatype : 'json'
})

Upvotes: 2

adeneo
adeneo

Reputation: 318162

Turn off caching

function Inicializar() {
   $("#wait").show();

    $.ajax({ type: "POST",
        url      : "index.aspx/Iniciar",
        cache    : false,
        datatype : 'json'
    }).done(function (response) {
        $("#wait").hide();
        cargardatos(response.d);
    });
}

$(document).ready(function () {
    Inicializar();
});

Upvotes: 0

Related Questions