Search code examples
jqueryajaxjquery-callback

How to call a JS function after AJAX call to database is completely done


I'm having trouble with an AJAX call.

var updateData = function(param, value)
{
    $.ajax({
    type: 'GET',
    url: ajax_router,
    data: 'param='+param+'&value='+value,
    success: reloadList()
    });
}

Unfortunately the reloadList() function is called too soon. The page doesn't reload with the new data. When I hit F5 the new data is here so the database update works, it's just a matter of calling the reloadList() function at the right time.

I also tried with complete: reloadList() but it didn't work either.

Any ideas ? Thanks !


Solution

  • Remove the brackets from reloadList().

    You're calling the function immediately, instead of passing the function itself in the success: handler.