Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

nuAjax

Questions related to using nuBuilder Forte.
Locked
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

nuAjax

Unread post 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.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuAjax

Unread post 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
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: nuAjax

Unread post 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>'); 
        }
    }
}
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuAjax

Unread post 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
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: nuAjax

Unread post by toms »

Thanks to your example, I managed to get things going. :D
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuAjax

Unread post by admin »

Cool.
Locked