Highlighted

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

New Here ,
Nov 03, 2018

Copy link to clipboard

Copied

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.

Views

449

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

New Here ,
Nov 03, 2018

Copy link to clipboard

Copied

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.

Views

450

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 03, 2018 0
Adobe Community Professional ,
Nov 04, 2018

Copy link to clipboard

Copied

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');

    }                    

});

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 04, 2018 0
New Here ,
Nov 04, 2018

Copy link to clipboard

Copied

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 .

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 04, 2018 0
Adobe Community Professional ,
Nov 06, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 06, 2018 0
New Here ,
Nov 06, 2018

Copy link to clipboard

Copied

formdata is the data on the modal popup. once user clicks the "change password" button, i am serializing the form data into json and sending it to the cfc. for eg. {"newpassword": "test1"}. the serialize is working ok. don't worry about that.

the function looks like this below:

    <cffunction name="ChangePassword" access="remote" output="true" returntype="string"  returnformat="json" hint="Adds/Edits User Info .">       

        <cfargument name="jsonFormData" type="string" required="yes" hint="user."/>


        <cfset retJSON = '{"Result": "Error","message": "Action Failed", "TotalRecordCount":0}'>

       

        <!--- start error handling --->

        <cftry>

            <cfstoredproc procedure="******************" datasource="#session.dsn#">

                <cfprocparam type="IN" dbvarname="@UserID" value="#session.userID#" cfsqltype="cf_sql_varchar" >

                <cfprocparam type="IN" dbvarname="@XMLData" value="#ConvertArrToXML(deSerializeJSON(jsonFormData))#" cfsqltype="cf_sql_varchar" >

                <cfprocparam type="IN" dbvarname="@LastUpdatedUserID" value="#session.userID#"cfsqltype="CF_SQL_VARCHAR">

                <cfprocparam type="OUT" dbvarname="@ret" cfsqltype="cf_sql_integer" variable="ret">

            </cfstoredproc>

           

           

            <cfif #ret# eq 1>

                <cfset retJSON = '{"Result": "OK","message": "Action Successful","TotalRecordCount":1}'>

            <cfelse>

                <cfset retJSON = '{"Result": "Error","message": "Action Unsuccessful","TotalRecordCount":0}'>

            </cfif>

                       

                   

           

        <cfcatch type="database">


            <cfset retVar = REMatch("\^.+\^", #cfcatch.queryError#)>           

            <cfset retJSON = '{"Result": "Error","message": "#Replace(retVar[1],"^","", "all")#","TotalRecordCount":0}'>

           

           

        </cfcatch>

        </cftry>

        <cfreturn retJSON>

    </cffunction>

  

jsonFormDat

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 06, 2018 0
New Here ,
Nov 07, 2018

Copy link to clipboard

Copied

Hi BKBK,

I have resolved this issue. i had to modify the application.cfc onrequeststart event and to add this in there "

<cfif LCase(Right(ARGUMENTS.TargetPage,3)) EQ "cfc"> 
<cfset StructDelete(THIS,"OnRequest")>
<cfsetting showdebugoutput="no"> </cfif>

I guess coldfusion doesn't handle ajax calls to cfc good. And this has to be added to remove the debugging information from the response.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0
LEGEND ,
Nov 07, 2018

Copy link to clipboard

Copied

nishantgupta01  wrote

I guess coldfusion doesn't handle ajax calls to cfc good. And this has to be added to remove the debugging information from the response.

I'm not so sure about this.  We are using CF11, I make AJaX calls to CFCs all the time, and as long as the components folder is within the webroot I've never had any debugging info passed.  But we've got debugging info turned off.  Don't want to give any error details to potential hackers/script kiddies.  Details are emailed in CFDUMP form and the user sees only a generic error message if anything goes awry.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0
New Here ,
Nov 07, 2018

Copy link to clipboard

Copied

wolfshade,

I am also making ajax call to cfc in most of my pages and it is working no issues. This problem was only happening inthe login page. My "change password" has same exact code as the login page and it was working fine. But now the login page is also working after adding the code to the application.cfc. I removed this line from the code above "<cfset StructDelete(THIS,"OnRequest")>" and only kept this line "<cfsetting showdebugoutput="no">" and still everything is working. So it must have something to do with showdebugoutput setting.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0
LEGEND ,
Nov 07, 2018

Copy link to clipboard

Copied

nishantgupta01  wrote

So it must have something to do with showdebugoutput setting.

It's got to be the showdebugoutput.  I believe that adds output to everything.  Been decades since I used showdebugoutput.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 07, 2018 0
New Here ,
Nov 09, 2018

Copy link to clipboard

Copied

hi wolfshade,

I already have showdebugoutput = "no" in my application.cfc. but i still had to add it to the onrequeststart function. see my application.cfc below


<cfcomponent>

    <cfset this.name="Recovery" >

    <cfset this.clientmanagement=false >

    <cfset this.sessionmanagement=true >

    <cfset this.setclientcookies=true >

    <cfset this.setdomaincookies=false >

    <cfset this.sessiontimeout=1*60*60 >

    <cfset this.scriptProtect="all">

    <cfsetting showdebugoutput="no">

   

    <!--- set global values that will be used throughout the application --->

        <cfset request.imageArtworkPath="images/">

        <cfset request.message="">


        <!--- use access based cfc --->

        <cfset request.cfcPath="Recovery">

        <!--- not available --->

        <cfset request.na="-">

   

    <cffunction name = "onRequestStart">

        <!--- Generated by login wizard --->

        <cfargument name = "thisRequest" required="true"/>


    <!--- user defined functions --->

        <cfif LCase(Right(ARGUMENTS.thisRequest,3)) EQ "cfc">          

            <cfsetting showdebugoutput="no">

        <cfelse>

            <!--- user defined functions --->

            <cfinclude template="webroot/shared/udFunc.cfm">

           

            <!--- Common function --->

            <cfinclude template="webroot/extensions/components/common.cfc">

           

            <!--- Login --->   

            <cfinclude template="webroot/mm_wizard_application_include.cfm">

        </cfif>


    </cffunction>


    <cffunction name="onRequest">

        <cfargument name="targetTemplate" type="String" required="true" />

       

       


        <!--- log user out if they click 'logout' or if their session has expired --->

        <cfif isDefined("url.logout") or (len(getAuthUser()) and not isDefined("session.fullname"))>

            <cfset structClear(session)>

            <cflogout>

            <cfif isDefined("url.logout")>

                <cflocation url="index.cfm" addtoken="yes">

            </cfif>

        </cfif>

       

        <cfinclude template="#arguments.targetTemplate#">

    </cffunction>

   

</cfcomponent>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 09, 2018 0