簡體   English   中英

如何使用jQuery Ajax調用訪問兩個不同的XML文件

[英]How to access two different XML files with jQuery Ajax calls

我有兩個功能

function ShowCrossWord(var randN)
{
     randomnumber = randN;

     $(document).ready(function() {
       $.get("crosswords.xml",{},function(xml){
         $('crossword',xml).each(function(i) {  });
       });
     });
}

  function ShowLegend(var randN)
  {
    randomnumber = randN;
    $(document).ready(function() {
      $.get("legends.xml",{},function(xml){         
            $('legend',xml).each(function(i) {});
      });

    });
  }

我在同一個javascript文件中使用這些:

   var randomNumber=Math.floor(Math.random()*233);   
   ShowCrossWord(randomNumber);
   ShowLegend(randomNumber);

他們似乎都不起作用。 解決辦法是什么。

您期望發生什么,實際發生了什么?

所以我可以看到:

  • 您永遠不會對XML數據做任何事情。 我想它甚至沒有被退還?
  • 您可能需要將dataType屬性指定為“ xml”,以便jQuery知道服務器返回的數據類型。

我建議您仔細檢查以上幾點,然后使用FireBug進一步縮小問題范圍。

我想您從服務器發送的XML的模仿類型是錯誤的。 做到這一點非常挑剔,否則XML不會在客戶端上解析。

您可以嘗試注冊成功和錯誤的回調函數,並記錄錯誤消息和XMLHTTPRequest對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM