In this code I have a callback undefined error:
function getPacakage(callback){
var sendurl={address:'http://ip/bms/data.php?result=10&order=28'}
var temp_selpkg_group=[];
var temp=[];
$.ajax({
type:"GET",
url:"dummycall.php",
data:sendurl,
success:function(xml){
pkg_sel[0] = $(xml).find('test1').text();
pkg_sel[1] = $(xml).find('test2').text();
pkg_sel[2] = $(xml).find('test3').text();
$(xml).find('packageitem').each(function(){
temp_selpkg_group=[];
temp_selpkg_group[0]=$(this).find('group').text();
temp_selpkg_group[1]=$(this).find('Qty').text();
temp[cnt_pkgitem]=temp_selpkg_group;
cnt_pkgitem++;
});
callback.call(null,temp);
},//sucess ends
error: function(){
alert("An error occurred while processing XML file.");
} //error ends..
}); //ajax ends...
}
Here is how I’m calling the function:
$(document).ready(function (){
$(function() {
$( "#accordion" ).accordion();
});
getPacakage(function(temp){
sel_pkg_group=temp;
fillOptionList();
});
});//document ready ends..
If I refresh page (Ctrl+F5) 2 to 3 time then the data is displayed.
As Ajax is an asyc task we need to complete one ajax task first and the call the function to use the array which is intialized in ajax ,so just add async:false in ajax.
this will stop async and the other methos will be called only when one complete , this works for me may be helpfull to my other friends ,happy coding