Javascript .ajax调用在chrome中不起作用

Javascript .ajax调用在chrome中不起作用,javascript,jquery,html,ajax,google-chrome,Javascript,Jquery,Html,Ajax,Google Chrome,我有一个ajax调用,它解析xml文件。我已经将async设置为false,但它仍然不工作。在ajax调用之前和之后,我都收到了警报,它似乎在连续工作。谁能告诉我哪里出了问题。下面是我正在做的代码段 var i = 0; var xmlLength = 0; var arr = new Array(); alert("1"); $.ajax({ type: "GET", url: "sample.xml", async: false, dataType: "xml", s

我有一个ajax调用,它解析xml文件。我已经将async设置为false,但它仍然不工作。在ajax调用之前和之后,我都收到了警报,它似乎在连续工作。谁能告诉我哪里出了问题。下面是我正在做的代码段

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");
var i=0;
var xmlength=0;
var arr=新数组();
警报(“1”);
$.ajax({
键入:“获取”,
url:“sample.xml”,
async:false,
数据类型:“xml”,
成功:函数(xml){
$(xml).find('CD').each(函数(){
警报(“2”);
i=i+1;
xmlength+=1;
var标题;
var getTo;
艺术家;
葛通奈德;
var$allToElements='TO';
var country=$(this.find('country').text();
getTo=$(this.find('TO');//.text();
如果(getTo.length>1){
var$divId=“窗口”+i;
$('')
.append(“”)
.append(“”)
.append(“”)
.append(“”)
.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')。每个(函数(){
var$name=$(this.text();
j+=1;
$('div#window'+i).append($).text($name));
});
}否则{
var$divId=“窗口”+i;
$('')
.append(“”)
.append(“”)
.append(“”)
.append(“”)
.append($).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;
});//查找结束
}
}); //ajax函数结束
var j;
警报(“3”);


谢谢

注意,Google Chrome不能通过XmlHttpRequest(用于ajax和
jQuery.ajax
函数)处理本地文件。因此,无法加载路径类似于
file://...

请注意,Google Chrome不能通过XmlHttpRequest(用于ajax和
jQuery.ajax
函数)处理本地文件。因此,无法加载路径类似于
file://...

控制台给了您什么错误?您使用的是Web服务器(http://)还是仅使用文件://。对于ajax,您需要在类似apache的Web服务器上运行。它不能直接打开file://What 运行时你会收到一系列警报吗?@saturngod:我正在使用apacheweb服务器并在上运行localhost@arxanas:我已将i声明为var并将其设置为0控制台给了您什么错误?您正在使用Web服务器(http://)还是仅使用文件://打开。对于ajax,您需要在类似apache的Web服务器上运行。它不能直接打开file://What 运行时你会收到一系列警报吗?@saturngod:我正在使用apacheweb服务器并在上运行localhost@arxanas:我已将i声明为var并设置为0@seperansky:中没有xmlHttpRequestapplication@arxanas:这意味着我无法在google chrome浏览器中运行应用程序?@unix\u user It取决于:您试图访问的文件是否为本地文件?不管是哪种方式,答案可能是如果你足够努力,你可以。@arxanas:是的,文件是本地的。xml文件位于my.js所在的同一目录中file@SperanskyDanil当前位置我错了。我没有正确地检查它。它是file://而不是localhost。非常感谢您指出这一点。@seperansky:在这个文档中没有xmlHttpRequestapplication@arxanas:这意味着我无法在google chrome浏览器中运行应用程序?@unix\u用户这取决于:您试图访问的文件是本地的吗?不管是哪种方式,答案可能是如果你足够努力,你可以。@arxanas:是的,文件是本地的。xml文件位于my.js所在的同一目录中file@SperanskyDanil当前位置我错了。我没有正确地检查它。它是file://而不是localhost。非常感谢你指出这一点。