开发者

jQuery $.post callback function calling location.reload() without using an anonymous function

Consider the following:

wrap callback in anonymous function (works)

$('#updateView').change(function(e) {
  $.post(URL + "actions/updateView.php",
    { view: $(this).val() },
    function() {reloadPage();}
  );
});

call function directly (cookie is set but doesn't seem to update before page reload)

$('#updateView').change(function(e) {
  $.post(URL + "actions/updateView.php",
    { view: 开发者_StackOverflow中文版$(this).val() },
    reloadPage()
  );
});

For what i am doing the first works but the second doesn't. the function reloadPage (shown below) reloads the page after updateView.php updates a cookie. For some reason using the second version the cookie isn't getting set before the page is reloading. but if i refresh the page my self, it "finds" the new value for the cookie.

is there something in the jQuery docs about this? I couldn't find anything.

function reloadPage() {location.reload(true);}

I am using jQuery 1.4.1, Php 5.2.5, Apache 2.2.11


Try this:

$('#updateView').change(function(e) {
  $.post(URL + "actions/updateView.php",
    { view: $(this).val() },
    reloadPage
  );
});

reloadPage() isn't a function name, but reloadPage is :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜