I have these function in jQuery :
The problem is I unable to pass the variable branchaddress outside of the function. Can only display inside $.get(); Is there any way I can passed the value or I need to find another way to do it ?
Here's my full code for
function.js
function approveData(name, branch,email){
    var branchaddress = "";
    $.get('php/ajax-get-branch-address.php', {branch_address: branch}).done(function(data){
            ar = JSON.parse(data);
            branchaddress = ar.BRANCH_ADDRESS;
            // alert(branchaddress);
    });
    // alert(branchaddress);
    $.get("php/ajax-mail.php", 
            {
                "type": 'APPROVE', 
                "name": name,
                "branchaddress": branchaddress,
                "email"         : email
            }
        );  
}
ajax-get-branch-address.php
<?php
$connStr = "";
$conn = oci_connect("", "", $connStr);
$branch_address = $_GET['branch_address'];
$query = "select * from table where branch_name = '".$branch_address."' "; 
$result = oci_parse($conn, $query);
oci_execute($result);
$row = oci_fetch_array($result);
echo json_encode($row);
?>
ajax-mail.php
<?php
$to = $_GET['email']; 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Sender <noreply@mail.com>"; 
if($_GET['type'] == "APPROVE"){
    $message =
        "<html>
            <head></head>
            <body>
                    <table style='font-family:Century Gothic'>
                    <tr>
                        <td style='padding-bottom:5%;'>Dear $_GET[name],</td>
                    </tr>
                    <tr>
                        <td style='padding-bottom:5%;'>Thank you. Detail as below :</td> 
                    </tr>
                    <tr>
                    <td style='padding-bottom:5%;'>
                        <table style='margin:0 10%;font-family:Century Gothic;'>
                            <tr>
                                <td>Officer Name</td>
                                <td style='min-width:10px'></td>
                                <td>:</td>
                                <td style='min-width:10px'></td>
                                <td>$_GET[name]</td>
                            </tr> 
                            <tr>
                                <td>Branch Address</td>
                                <td style='min-width:10px'></td>
                                <td>:</td>
                                <td style='min-width:10px'></td>
                                <td>$_GET[branchaddress]</td>
                            </tr> 
                        </table> 
                    </td> 
                    </tr> 
                    <tr>
                        <td>Thanks and regards;</td> 
                    </tr> 
                </table> 
            </body> 
        </html>";
}      
echo $message;
mail($to, "Sender", $message, $headers, "-f noreply@mail.com");
?>
Appreciate if someone can help to solve this problem.
P/S : I already search for this problem but having the difficulty to understand the suggestion answers.
 
     
    