Reputation: 309
I am having a ajax call which parses the xml file. I have set the async to false, but still it is not working. I had the alert before and after the ajax call and it seems to be working in succession. can any one please let me know where I am going wrong. Here is the code segment that what I am doing
var i = 0;
var xmlLength = 0;
var arr = new Array();
alert("1");
$.ajax({
type: "GET",
url: "sample.xml",
async: false,
dataType: "xml",
success: function (xml) {
$(xml).find('CD').each(function () {
alert("2");
i = i + 1;
xmlLength += 1;
var title;
var getTo;
var artist;
var getToNode;
var $allToElements = 'TO';
var country = $(this).find('COUNTRY').text();
getTo = $(this).find('TO'); //.text();
if (getTo.length > 1) {
var $divId = "window" + i;
$('<div class="window" id="window' + i + '" />')
.append('<div class="topright" id="topright' + i + '"/>')
.append('<div class="topleft" id="topleft' + i + '"/>')
.append('<div class="bottomright" id="bottomright' + i + '"/>')
.append('<div class="bottomleft" id="bottomleft' + i + '"/>')
.appendTo('div#demo1');
var countr = $(this).find('COUNTRY').text();
$('div#topright' + i).append(countr);
$('div#topleft' + i).append('NW');
$('div#bottomleft' + i).append('SW');
$('div#bottomright' + i).append('SE');
var j = 0;
$(this).find('TO').each(function () {
var $name = $(this).text();
j += 1;
$('div#window' + i).append($('<p id="to' + i + '">').text($name));
});
} else {
var $divId = "window" + i;
$('<div class="window" id="window' + i + '" />')
.append('<div class="topright" id="topright' + i + '"/>')
.append('<div class="topleft" id="topleft' + i + '"/>')
.append('<div class="bottomright" id="bottomright' + i + '"/>')
.append('<div class="bottomleft" id="bottomleft' + i + '"/>')
.append($('<p id="to' + i + '">').text(getTo.text()))
.appendTo('div#demo1');
var countr = $(this).find('COUNTRY').text();
$('div#topright' + i).append(countr);
$('div#topleft' + i).append('NW');
$('div#bottomleft' + i).append('SW');
$('div#bottomright' + i).append('SE');
}
arr[i] = getTo;
}); //end of find
}
}); //end of ajax function
var j;
alert("3");
Thanks!
Upvotes: 0
Views: 2107
Reputation: 30453
Notice that Google Chrome does not work with local files by XmlHttpRequest (which is used for ajax and jQuery.ajax
function). So you cannot load file which path looks like file://...
.
Upvotes: 4