开发者

JQuery Mobile Caching issues, onClick not fired unless page is reloaded

Ok, let me first off say I'm assuming this is related to caching. but i'm not 100% sure

I am working on a mobile site which you can view here

The issue is logging out, well clicking the logout button to be precise.

If the user logs in, navigates to ANY page on the site, then attempts to click logout (see function below) they will get nothing. No post, no relocated, and if i put an alert in the function it is not run. nothing. UNLESS the user reloads the page and attempts to log out.

function submitLogout(){
    $.post("../server/log.php", { uaction: "logout" },function(data){
        window.location = "/index.php";
    }); 
}

Steps to reproduce:

  1. Visit this website
  2. Click Login
  3. Login using username foo, password bar
  4. Navigate to any of the links provided.
  5. Click Logout

Now if you do want to see the function call as expected just reload the page and click logout.

Or, at step 4, instead of navigating away click Logout

** To Clarify Again ** The submitLogout function is never actually run; If i change the function to be

function submitLogout(){
    alert("wtf");
    $.post("../server/log.php", { uaction: "logout" },function(data){
        window.location = "/index.php";
    }); 
}

The alert is neve开发者_开发知识库r called. If there is a problem with the relative path I wouldn't know. The post is never called. I have added a breakpoint on the function and I can confirm it is never entered.


You use a relative reference to your log.php with: "../server/log.php"

You can rely on relative paths, but always think of what will be the referential. In this case, it's the location of the current URL, client-side, not the path of the JS file.

The solution would consist, in your case, in replacing the .. part with /bin, which is the folder in which your endpoint is located.

Here is the full fix:

function submitLogout() {
  alert('submitLogout is triggered');
  $.post("/bin/server/log.php", { uaction: "logout" },function(data){
    window.location = "/index.php";
  }); 
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜