我第一次使用JavaScript / AJAX,所以我试图找出一些最佳实践。
现在,在我看来,我显示一个数据表,然后当一个外部服务器的调用返回一个值(在这种情况下是帐户余额)。我更新数据表。
现在,这是完美的,但我遇到了一个问题。我想还使用新的"余额"来更新我的数据库。发现了。但是,我想在之后执行 ajax调用。
我应该在视图中的ajax调用中的某个位置执行此操作吗? (这感觉不对)或者我应该将此更新插入正在调用的php文件中吗?
这是view / ajax调用:
<script>
function getBalance(){
$.get("assets/balance.php", "", function(data){
$('#balance').html(data);
// alert(data);
});
}
getBalance();
</script>
这是 balance.php :
<?php
include "../protected/components/helpers.php";
/**
*@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 = '<soapenv:Envelope>...';
// 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);
}
echo $result = BalanceCall($msisdn, $pin);
?>
我知道$.get
函数的使用方式如下:
$.get(URL,data,function(data,status,xhr),dataType)
我应该在传递数据时执行此操作吗?