Skip to main content
Participating Frequently
November 3, 2018
Question

using ajax from the mm_wizard_login.cfm page. Not returning the json

  • November 3, 2018
  • 1 reply
  • 1443 views

Hello,

I am using coldfusion 11. I inherited an application which uses the mm_wizard_login coldfusion feature  for their login functionality. Now i have to implement the change password functionality in this application.  So if the user logs in and the application finds that this user is logging in for the first time, it should redirect the user to the change their initial password.

So i decided to use a jquery third party modal plugin.

I have added the jquery plugin functionality in the mm_wizard_login.cfm page. During the authentication process, the scenario where the user needs to change password, the mm_wizard_authenticate.cfc denies the login and redirects them back to mm_wizard_login.cfm page and then the plugin opens up and allows user to type in their new password. After the user clicks the submit, in jquery i am intercepting their submit and i am making an ajax call to another cfc which is accepting the new password and calling a sql server SP to change their password. this cfc method returns json back the ajax but the returning value is not json, it is returning the html for the mm_wizard_login.cfm page itself.

Everything is working, except the ajax call is not returning json.

In chrome dev tools, i went into the network tab and under response tab, It is returning back the html for mm_wizard_login.cfm page. I don't understand this.

Here is my ajax call below:

var refData = $.ajax({

                            url: 'testmethod.cfc', 

                            method: 'POST',  

                            dataType: 'json',

                            data:{

                                method:'ChangePassword', //Call the method                     

                                jsonData: JSON.stringify($(formdata).serializeArray())


                            }

                        })

                        .done (function (d) {


                            if (d.Result == 'OK')

                                $("#modal-custom").iziModal('#modal-custom','setTitle', d.message);

                                $("#modal-custom").iziModal('#modal-custom','close');

                            else{                                  

                                changePwd_ErrorHandler(d.message);

                            }


                        })

                        .fail (function (XMLHttpRequest, textStatus, errorThrown) {

                            changePwd_ErrorHandler(textStatus + '. Please try again');

                        });

After nothing worked then i just tried a basic ajax call from my mm_wizard_login.cfm page, here it is below:

                var test = $.ajax({

                                url: 'testmethod.cfc',

                                method: 'POST'

                                dataType: 'json',

                                data:{

                                    method:'MethodTest', //Call the method


                                }

                         })

                         .done (function (d) {

                            

 

                         })

                         .fail (function (XMLHttpRequest, textStatus, errorThrown) {

                              alert('Unable to change password. Please try again');

                         });    

This is not working either. It is returning the same thing, not json but the html content of mm_wizard_login.cfm. Please help.

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
November 4, 2018

Use a structure such as:

var refData = $.ajax({

    type: "post",

    url: 'testmethod.cfc?method=ChangePassword',

    contentType: "application/json",

    data: JSON.stringify($(formdata).serializeArray()),    

    success: function (d) {

        if (d.Result == 'OK') {

              $("#modal-custom").iziModal('#modal-custom','setTitle', d.message);

              $("#modal-custom").iziModal('#modal-custom','close');

        } else {                                

              changePwd_ErrorHandler(d.message);

        }

    },

    error: function (XMLHttpRequest, textStatus, errorThrown) {

        changePwd_ErrorHandler(textStatus + '. Please try again');

    }                    

});

Participating Frequently
November 4, 2018

Hi BKBK,

Thanks for the response. I implemented your solution but i am getting the same issue. In chrome dev tools, i went into the network tab and under response tab, i am still getting the html for my mm_wizard_login.cfm page.

After  giving it some thought, could it be a problem that i am not logged into my application because i implemented the same functionality for my "change password" webpage after the user logs in and that functionality is working with no issues.

Another thought is that the mm_wizard_login.cfm is using mm_wizard_authenticate.cfc to do the authentication and that is happening before  the user logs in .

BKBK
Community Expert
Community Expert
November 6, 2018

It is difficult to say, when one doesn't have the details. What does formdata stand for? Could you show us the function changePassword?