Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$.ajax({ type:"GET", url: 'resourse/test.xml', dataType: 'xml', async: true, success: function(data){
我想从 xml 文件中获取数据。这样我就可以将数据存储在 var 中,一个线程可以写入 var,而另一个线程可以将 var 中的数据写入图表。怎么做。我尝试了几种方法,但似乎成功下的事件在加载整个 xml 文件之前就停止了。
我的猜测是您正在读取 ajax 调用范围之外的变量,因此它将在 ajax 调用实际完成之前被调用。
js是异步的
$.ajax(...); //fires off $.ajax(...); //This one will fire off before the first ajax call is finished
还可以尝试使用断点单步执行您的 js 代码,您将很快看到会发生什么......