1

I seem to be encountering a situation where multiple asynchronous ajax call are causing cfwheels to return an action not found error. I noticed when I add async:false to my ajax call I get a successful response but when I don't add that I randomly get an error response.

This code works fine when other ajax calls are being processed but it takes longer to load due to the async setting.

    var checkLogin = function(){
         var loggedin = false;

         loginValidated = true;

         //Check login status
         $.ajax({
           type: "POST",
           url: '/loginAjax/validateLogin?format=json',
           global: false,
           async: false,
           success: function(data) {
              if (data.loggedIn) {
                 loggedin = true;
               }
           }
         });

return loggedin;
};

This fails randomly, notice I removed the async setting:

    var checkLogin = function(){
      var loggedin = false;

    loginValidated = true;

$.ajax({
  type: "POST",
  url: '/loginAjax/validateLogin?format=json',
  global: false,
  success: function(data) {
    if (data.loggedIn) {
        loggedin = true;
    }
  }
});

return loggedin;
};

Here is the action I am calling:

    <cffunction name="validateLogin">
    <cfset var returnObj = {}>
    <!--- Set Return Data --->
    <cfset returnObj["loggedIn"] = false>

    <cfif StructKeyExists(SESSION.User, 'loggedIn')>
        <cfset returnObj["loggedIn"] = true>
    </cfif>

        <cfset renderWith(returnObj)>
    </cffunction>

Any help is appreciated. :)

osekmedia
  • 633
  • 7
  • 14

1 Answers1

1

Is this in production or design mode? Common ajax issues are usually to do with the an ajax request firing before the framework has fully loaded when in design mode, which means your controller can occasionally be called before all the routes etc are loaded.

Neokoenig
  • 1,102
  • 7
  • 16
  • This is in development mode and design mode. I have not turned on production mode for testing yet because the system utilizes a set of API's and once in production they will all connect to the live API's and not the development ones. I will have to try out testing mode and see if I still have the same issues. – osekmedia Oct 16 '13 at 16:39
  • Yep, development and design modes don't cache the framework, they reload the CFCs each time, so I'd definitely try it! – Neokoenig Oct 16 '13 at 17:39
  • Great stuff :) -Enjoy wheels! – Neokoenig Oct 16 '13 at 22:08