Page 1 of 1

nuAjax

Posted: Fri Jan 12, 2018 5:36 am
by toms
Hi,

nuBuilderPro has a nuAjax function:

function nuAjax(pCode, pFunctionName, pOptions)

"This function runs the PHP Function in pCode and optionally runs a Javascript function using the set value of $nuParameters within the PHP Function as a parameter"
http://wiki.nubuilder.net/nubuilderv3/i ... Name.5D.29

How can I use it in nuBuilderForte? I don't see any information on the nuBuilderForte wiki page.

Re: nuAjax

Posted: Fri Jan 12, 2018 7:06 pm
by admin
toms,

Good question.

You can use nuRunPHPHidden()...
http://wiki.nubuilder.net/nubuilderfort ... nPHPHidden

It will run a Procedure without opening another Browser window.

You can use nuJavascriptCallback() inside that Procedure to run Javascript after the Procedure is complete...
http://wiki.nubuilder.net/nubuilderfort ... ptCallback

Steven

Re: nuAjax

Posted: Sun Jan 14, 2018 10:05 am
by toms
I don't quite understand how to use this nuJavascriptCallback() - probably due to the lack of profound js-knowledge.

My goal is to build a cascaded dropdown as shown in this example (for v3)
http://forums.nubuilder.cloud/viewtopic.p ... jax#p14320

Following the example, I created a PHP Procedure with the code "find_models".
In a dropdown, I attached an onchange event handler that runs the procedure:

Code: Select all

nuRunPHPHidden("find_model");
Where and how exactly do I implement nuJavascriptCallback()? The pollute_models() should be called after nuHiddenPHP() has returned from the server, passing the param.

Code: Select all

function pollute_models(param){
    
    $('#car_model').empty();
    $('#car_model').append('<option value=""></option>');
    
    if(param!=''){
        var json_data = JSON.parse(param);
        
        for(var i=0; i < json_data.length;i++){  
            $('#car_model').append('<option value="'+json_data[i][0]+'">'+json_data[i][1]+'</option>'); 
        }
    }
}

Re: nuAjax

Posted: Sun Jan 14, 2018 4:50 pm
by admin
toms,

Here is a Procedure that will populate a Select Object called thelist based on an Object called thelanguage

It makes Javascript and runs it back in the Browser.

Code: Select all


$a  = [];
$s  = "SELECT * FROM zzzzsys_translate WHERE trl_language = '#thelanguage#'";
$t  = nuRunQuery($s);

while($r = db_fetch_object($t)){
    $a[]    = $r->trl_english;
}

$j  = json_encode($a);

$js = "


populate_phrases();

function populate_phrases(){

    var p = $j;
    
    $('#thelist').empty();

    if(p != ''){

        for(var i = 0; i < p.length;i++){  
            $('#thelist').append('<option value=\"' + p[i] + '\">' + p[i] + '</option>'); 
        }
        
    }
    
}

";

nuJavascriptCallback($js);


Steven

Re: nuAjax

Posted: Tue Jan 16, 2018 1:08 am
by toms
Thanks to your example, I managed to get things going. :D

Re: nuAjax

Posted: Tue Jan 16, 2018 1:09 am
by admin
Cool.