nuAjax

Questions related to using nuBuilder Forte.

nuAjax

Postby toms » Fri Jan 12, 2018 2:06 pm

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.
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuAjax

Postby admin » Sat Jan 13, 2018 3:36 am

toms,

Good question.

You can use nuRunPHPHidden()...
http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript#nuRunPHPHidden

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/nubuilderforte/index.php/PHP#nuJavascriptCallback

Steven
admin
Site Admin
 
Posts: 2469
Joined: Mon Jun 15, 2009 9:53 am

Re: nuAjax

Postby toms » Sun Jan 14, 2018 6:35 pm

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)
viewtopic.php?f=13&t=8898&p=14320&hilit=nuajax#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>');
        }
    }
}
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuAjax

Postby admin » Mon Jan 15, 2018 1:20 am

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
admin
Site Admin
 
Posts: 2469
Joined: Mon Jun 15, 2009 9:53 am

Re: nuAjax

Postby toms » Tue Jan 16, 2018 9:38 am

Thanks to your example, I managed to get things going. :D
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuAjax

Postby admin » Tue Jan 16, 2018 9:39 am

Cool.
admin
Site Admin
 
Posts: 2469
Joined: Mon Jun 15, 2009 9:53 am


Return to General