I'm running into an issue of where I would like to update a database after an ajax call has been fully made. In order to find the value that I want to update the database with I have to make a SOAP call (or server request) which take some time. I'd like to instead use the value that was found in that ajax call and then store that in my database.
Here is my ajax call
<script>
function getBalance(){
$.get("assets/balance.php", "", function(data){
// # means an id, but a . would mean a class
// .html means replace the html of id with the balance
$('#balance').html(data);
// alert(data);
});
}
getBalance();
</script>
and here is the balance.php that is being called
/**
*@method CheckBalance() : this method helps to get the balance info of the tigo cash subscriber using tigo rwanda middleware
*@param string $msisdn : this is the mobile number of the tigo cash subscriber
*@param string $pin : this is the pin number of the tigo cash account
*@return returns the decoded answer either as the balance (int) or a warning (string)
*/
function BalanceCall($msisdn,$pin){
//Store your XML Request in a variable
$input_xml =
.... some xml ....
// url of the server the request is going to
$url = "http://10.138.84.138:8002/osb/services/GetBalance_1_0";
// returns a long xml string reply
$xmlstring = curl_exec($soap_do);
// this returns either the balance (int) or an error (string)
return $result = Helpers::decodeBalanceString($xmlstring);
}
Now would it be appropriate to then update my database from within balance.php? I'd like to keep my database updated - and I don't know a way to call a function like " updatDatabase" i in the controller after the render because it will JS run before the java script function finishes.