Note that there are some explanatory texts on larger screens.

plurals
  1. PO$.ajax( { async : false } ) request is still firing asynchronously?
    primarykey
    data
    text
    <p>I got a little problem here guys. I'm trying to implement the following scenario: <br /></p> <ol> <li>A user opens the home page and sees a list of other users and clicks to add one to his friend list.</li> <li>I issue an Ajax request to a server resource to validate if the user is logged in, if so, I issue another ajax request to another server resource to actually add it to the user's friend list.</li> </ol> <p>Sounds simple? Here's what I've done: I created a function <code>isLoggedIn</code> that will issue the first request to the server in order to determine if the user is logged in. I issue this request using <code>jQuery.ajax</code> method. Here's my function looks like:</p> <pre><code>function isLoggedIn() { $.ajax({ async: "false", type: "GET", contentType: "application/json; charset=utf-8", dataType: "json", url: "/isloggedin", success: function(jsonData) { alert("jsonData =" + jsonData.LoggedIn); return jsonData.LoggedIn; } }); } </code></pre> <p>The returned JSON is very simple, it looks like the following:</p> <pre><code>{ LoggedIn: true } or { LoggedIn : false } </code></pre> <p>Now this method, actually works and displays the alert correctly: <code>JsonData = true</code> if logged in, and <code>JsonData = false</code> if not logged in. Up to this point there's no problem, the problem occurs when I try to call this method: I call it like so:</p> <pre><code>$(".friend_set .img").click(function() { debugger; if (isLoggedIn()) { alert("alredy logged in"); trackAsync(); popupNum = 6; } else { alert("not logged in"); //always displays this message. popupNum = 1; } //centering with css centerPopup(popupNum); //load popup loadPopup(popupNum); return false; }); </code></pre> <p>Calling <code>isLoggedIn</code> always returns <code>false</code>, and it returns <code>false before the ajax request finishes (because the message</code>jsonData = true<code>is displayed after the message "not logged in". I made sure that the request is **NOT** Asynchronous by stating</code>async: false`! </p> <p>Apparently it's still working asynchronously, though. What am I missing here guys? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload