我有两个功能的问题。我只想chcekResults
在callAPI
完成后运行。
我的点击事件:
$("a#showA").click(function (e) {
e.preventDefault();
chceckResults(callAPI(apiKey));
});
和功能:
var Count = 0;
var ContractsArray = new Array();
function callAPI(yourAPIKey){
var enquiry = URL + yourAPIKey;
//alert(enquiry);
$.ajax({
url: enquiry,
type: 'GET',
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpCallback2",
complete: function (response, responseCode) {
},
success: function (json) {
$.each(json.Contracts, function (index, contract) {
// alert("Count before increament : " + Count);
// alert(contract.ContractCode);
ContractsArray[Count] = contract.ContractCode;
// alert("Count after increament : " + Count);
// alert("ContractsArray[Count]: " + ContractsArray[Count]);
Count++;
});
}
});
}
function chceckResults(){
alert("Count value in chceckResults : " + Count);
for(var i = 0; i <= Count; i++){
alert("ContractsArray[" + i + "]: " + ContractsArray[i]);
}
}
我只想chcekResults
在callAPI
完成后运行。我怎样才能做到这一点?