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

  • Home
  • SEARCH
  • 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 7795937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:12:58+00:00 2026-06-01T23:12:58+00:00

Im having a strange problem with the following code: function getTrxData(trx,inputPar,outputPar,callback) { var retorno

  • 0

Im having a strange problem with the following code:

function getTrxData(trx,inputPar,outputPar,callback) {

var retorno = {};

var URL = '/XMII/Runner?Transaction=' + trx;

var params = "";
for(key in inputPar) 
    params = params + "&" + key + "=" + inputPar[key];

if(!outputPar) 
    outputPar = "*";    

if(params)
    URL = URL + params;

URL = URL + '&OutputParameter=' + outputPar;        

$.ajax({
    type: "GET",
    url: URL,
    async: true,
    success: function(data){
        retorno.datos = $.xml2json(data);
        retorno.tipo    = 'S';          // Success
        retorno.mensaje = "Datos obtenidos correctamente";      
        callback(retorno);
    },
    error: function(jqXHR, textStatus, errorThrown){
        retorno.tipo    = 'E';          // Error
        retorno.mensaje = "Error: " + textStatus;   
        callback(retorno);
    }
});
}

function crearSelect(trx,inputPar,outputPar,selectID,campoTextoXX,campoValor,valorDefault,callback2) {
// At this point campoTextoXX exists and has a value
getTrxData(trx,inputPar,outputPar,function(retorno2) {

            // At this point campoTextoXX is an object equal to callback2

    if(retorno2.tipo == 'E') {
        callback2(retorno2);
        return false;
    }

    var options = "";
    var selected = "";

    $.each(retorno2.datos.Rowset.Row, function(k,v) {
        if(valorDefault == v[campoValor]) {
            selected = " selected='selected'";
        } else {
            selected = "";
        }
        options = options + "<option value='" + v[campoValor] + selected "'>";
        options = options + v[campoTextoXX];    
        options = options + "</option>";
    });

    $("#" + selectID + " > option").remove();
    $("#" + selectID).append(options);

    callback2(retorno2);

});

}

And the call is like this:

crearSelect("Default/pruebas_frarv01/trxTest",{letra:  'V'},"*",'selectID',"CustomerID",'OrderID','',function(retorno) {
alert(retorno.tipo + ": " + retorno.mensaje);
});

The problem is that campoTextoXX and campoValor dont get any value inside the callback function. Also, debugging in Chrome shows me that campoTextoXX has the value of the callers callback function:
alert(retorno.tipo + “: ” + retorno.mensaje);

I dont know what to do next.

Any ideas?

Thx

  • 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-06-01T23:13:00+00:00Added an answer on June 1, 2026 at 11:13 pm

    You might find it easier to mange the callback chain by exploiting $.ajax’s ability to behave as a jQuery Deferred.

    This allows us very simply to specify the “success” and “error” behaviour in the guise of request.done(…) and request.fail(…) at the point where getTrxData is called rather than inside getTrxData – hence the callback chain is (ostensibly) one level less deep.

    function getTrxData(trx, inputPar, outputPar) {
        inputPar.Transaction = trx;
        inputPar.OutputParameter = (outputPar || '*');
        return $.ajax({
            url: '/XMII/Runner?' + $.param(inputPar)
        });
    }
    
    function makeOptions(obj, selectID, campoTextoXX, campoValor, valorDefault) {
        var $option, selected, $select = $("#" + selectID);
        $("#" + selectID + " > option").remove();
        $.each(obj.datos.Rowset.Row, function(k, v) {
            selected = (valorDefault == v[campoValor]) ? ' selected="selected"' : '';
            $option = $('<option value="' + v[campoValor] + selected + '">' + v[campoTextoXX] + "</option>");
            $select.append($option);
        });
        return obj;
    }
    
    function crearSelect(trx, inputPar, outputPar, selectID, campoTextoXX, campoValor, valorDefault, callback) {
        var request = getTrxData(trx, inputPar, outputPar);
        request.done(function(data) {
            var obj = {
                datos: $.xml2json(data),
                tipo: 'S',// Success
                mensaje: "Datos obtenidos correctamente"
            };
            callback(makeOptions(obj, selectID, campoTextoXX, campoValor, valorDefault));
        });
        request.fail(function(jqXHR, textStatus, errorThrown) {
            var obj = {
                tipo: 'E',// Error
                mensaje: "Error: " + textStatus
            };
            callback(obj);
        });
    }
    
    crearSelect("Default/pruebas_frarv01/trxTest", {letra:'V'}, "*", 'selectID', "CustomerID", 'OrderID', '', function(retorno) {
        alert(retorno.tipo + ": " + retorno.mensaje);
    });
    

    You will see that this is essentially a refactored version of your original code, with significant simplification of the string handling in getTrxData, which appears to work correctly.

    The options code has been pulled out as a separate function, makeOptions, to make the new structure of crearSelect clearer. This is not strictly necessary and the code could be re-combined without penalty.

    Tested here insomuch as to make sure it loads and runs through to the “Error” alert, which it does successfully. Without access to the server-side script, I can’t test/debug the full ajax functionality so you may need to do some debugging.

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

Sidebar

Related Questions

I'm having a strange problem with the following code, I'm writing a game launcher
I'm having a strange problem. I have the following code: dbg(condwait: timeout = %d,
I'm having a strange problem with the following code works. Map<String, Object> map =
I am having a strange problem which I don't understand. I have the following
I'm having a strange problem with php PDO and mysql. I have the following
I'm having a strange problem where a user can enter the following text Test
I've been having this strange problem with apply lately. Consider the following example: set.seed(42)
I'm having a very strange problem with css3 border radius property. My following CSS
i am having a very strange problem while linking a webcam i xperience following
I'm having a strange problem that I can't figure out that popped up when

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.