我正在使用
JavaScript,jQuery和PHP.如何限制JavaScript函数执行一次?
我的MainJQuery文件有Ajax. display.php执行一段时间:
....
$.ajax({
type:'POST',
url: 'display.php',
data:'id='+id ,
success: function(data){
$("#response").html(data);
//Here Get_list should be execute only once.
get_list('get');
// Display should execute as usual
display();
}//success
}); //Ajax
.......
get.Php文件将值写入JavaScript:
print "
print " g_cost[g_cost.length]=new Array('STA-VES','East',4500);";
print " g_cost[g_cost.length]=new Array('STA-CRF','West',5400);";
print "";
?>
我的JavaScript函数具有PHP的以下值:
function get_list('get'){
for(var i=0;i
var temp = g_cost[i];
var Name = temp[0];
var direction = temp[1];
var cost = temp[2];
..
some code
...
}
function display(){
for(var i=0;i
alert(g_cost.length);
var temp = g_cost[i];
alert(temp[0]);
alert(temp[1]);
alert(temp[2]);
}
是否可以限制在jQuery Ajax成功部分中执行JavaScript函数?