Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:34:52+00:00 2026-05-30T06:34:52+00:00

I am calling a function with the following code: var resultz = nsEditor.updateStringCall(debtID, column2Change,

  • 0

I am calling a function with the following code:

var resultz = nsEditor.updateStringCall(debtID, column2Change, value2Change, 4, 10);

The function that is being called but doesn’t return a value

updateStringCall: function(pdebtID, pcolumn2Change, pvalue2Change, pmin, pmax){
    try {
        var resultz2 = 0;
        $.ajax({
            type: "POST",
            url: "Components/MintLibraries.cfc",
            dataType: "json",
            cache: false,
            data: {
                method: 'StringUpdate',
                val2Change: pvalue2Change.trim(),
                debtID: pdebtID,
                column2Change: pcolumn2Change,
                greaterThan: pmin,
                lesserThan: pmax,
                returnFormat: "json"
            },
            success: function(response) {
                resultz2 = 1;
                return resultz2;
            },  //end done
            error: function(jqXHR, textStatus, errorThrown){
                resultz2 = 0;
                return resultz2;
        }); //end ajax call
    } catch (e) {
        resultz2 = 0;
        return resultz2;
    }  //end trycatch
}, // end updateStringCall

This function uses the .ajax to call a coldfusion cfc method StringUpdate:

<cffunction name="StringUpdate" access="remote" output="false" returntype="any" >    
     <cfargument name="val2Change" type="string"  required="true" />
     <cfargument name="debtID"  type="string"  required="true" />
     <cfargument name="column2Change"  type="string"  required="true" />
     <cfargument name="greaterThan"  type="numeric"   required="false" />
     <cfargument name="lesserThan"  type="numeric"  required="false" />
     <cfset var debt2Pass = int(val(arguments.debtID)) />
     <cfset var updQuery = "" />
     <cfset var retValue = 0 />
     <cfset var iVal = 0 /><cfset var valError = '' />
    <cftry>
     
        <cfquery name="updQuery" datasource="#application.datasource#" result="qResults"    >
                Update dmf set #arguments.column2Change# =
                 <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.val2Change#"/>
                 where DebtID = 
                 <cfqueryparam cfsqltype="cf_sql_smallint" value="#arguments.debtID#"/>
        </cfquery> 
        <cfset retValue = 1 />    
     <cfcatch type="Any" >
                <cfset thrown = ThrowCFError(405,'debug',  'Error updating ' &  arguments.DebtID,arguments.val2Change & ', ' &  arguments.debtID & ',' & arguments.column2Change)  />
                  <cfset retValue = 0 />
         </cfcatch>
         </cftry>
    <cfreturn retValue />
</cffunction>

The query runs successfully but the js function doesn’t return a value (it shows up as undefined). Even if it gets an error, I would think I have accounted enough for that to at least get a return value.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:34:53+00:00Added an answer on May 30, 2026 at 6:34 am

    The function is not returning a value because the returns in your method are embedded inside callback functions. They are only returning from those callbacks, not from your main function. Consider, for example, your “success” callback:

    success: function(response) {
        resultz2 = 1;
        return resultz2;
    }
    

    This return is just returning from the success function… It doesn’t bubble up to your updateStringCall function.

    The reason it has to work this way is because ajax calls are asynchronous. Your method returns immediately while the request happens in the background. So in order to get the return value, you have to pass in a callback that has access to the value when it’s ready, and then call the callback from within the ajax callbacks instead of returning a value.

    So change your method definition to this:

    // Note I added a "callback" parameter
    function(pdebtID, pcolumn2Change, pvalue2Change, pmin, pmax, callback) { ... }
    

    And then in your ajax callbacks, call it instead of returning a value:

    success: function(response) {
        resultz2 = 1;
        callback(resultz2);
    },
    error: function(jqXHR, textStatus, errorThrown) {
        resultz2 = 0;
        callback(resultz2);
    });
    

    Finally, pass in a callback when you call this method:

    nsEditor.updateStringCall(debtID, column2Change, value2Change, 4, 10, function(resultz) {
        // Do something with resultz
    });
    

    One final note, if you are going to have that blanket try/catch in there, you should change that to use the callback also:

    catch (e) {
        resultz2 = 0;
        callback(resultz2);
    }
    

    But really, I’d recommend just taking that try/catch out altogether. I can’t see how that can possibly be helpful here. It will only hide actual problems with code that already has a better structure for error handling. I suspect you just put in there to debug this return problem, but if it was there already, just take it out.

    This is the world of event-driven functional programming! It’s a very common sort of structure in javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I have the following JS code: var reloadTimer = function (options) { var
HI, I am using the following code request.js var request; function runAjax(JSONstring) { //
I have the following code that I am playing with: <script type=text/javascript> var Dash
i am calling a jQuery plugin every 5 seconds with the following code var
Got the following code: $('#next_btn').click(function() { addUser(); }); //$('#next_btn').click function addUser() { var participant
I have the following code var playingStream:NetStream; function playBytes(bytes:ByteArray): void { var connect_nc:NetConnection =
Please help take a look at the following code, its working when calling function
The following jQuery code adds an event by calling a function scroll_position jQuery.event.add(window, scroll,
hi I have the following code: this.stop = function() { this.server.close(); var thisServer =
Using the following JQuery/AJAX function I'm calling a partial view when an option is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.