We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44437
    • 74 Posts
    Hey there,

    I have an Ajax Login that works well with Modx rev 2.2 but when I updated to Revo 2.3 I'm getting an unexpected result."syntaxError: unexpected <"

    Here is what I'm doing.

    1. I'm using jQuery to place my form in a variable. Example code is below
    	var myform = $('.myform form');


    2. Next, I serialize my "myform" variable and post the results using .post() API. "mylogin-page" has the Login snippet that will process the serialized data. Code is below
    $.post("mylogin-page", myform.serialize(), function(data){
    
    });


    The myform.serialize() is being POST successfully. That is not the issue.

    Here is the deal, on Modx rev 2.2 version, the Login Snippet would return a JSON if the user login information was correct. So what I'm doing as a validation test, if data is not a JSON, that means that there was a Login validation error found

    $.post("mylogin-page", myform.serialize(), function(data){
     try {
           var test = $.parseJSON(data); //Tries to parseJSON data, if data is not JSON, the Login validation failed on mylogin-page 
              } catch (e) {
                     
                $('#myerror').html(data);
                return false;
              }       
     //This mean that data is a JSON, therefore no validation errors were found                                        
     window.location.replace("home");
    });
    


    This code above works for Modx 2.2. HOWEVER, on modx Revo 2.3, even if the login credentials are correct, the Login Snippet returns a string/HTML instead of a JSON and it triggers an error.

    I have console.log(data) from both Modx 2.2 and Modx 2.3. One returns a JSON on success (revo 2.2) and the other a string on success.

    All my ajax forms are broken. Been trying at this for 2 days now. Any suggestions?