2015-06-21 96 views
0

我想所見hereXHR不加載

這一個XML文件加載到一個HTML文檔中的XML本地文件是我的腳本:

$(document).ready(function() { 
    $.ajax({ 
    type: "GET", 
    url: "Lemon_Bars.xml", 
    dataType: "xml", 
    success: xmlParser 
    }); 
}); 

function xmlParser(xml) { 
    $(xml).find("ing").each(function() { 
    $("div[data-role='content']").append("<p>" + $(this).find("qty").text() + "</p>"); 
    $("div[data-role='content']").append("<p>" + $(this).find("unit").text() + "</p>"); 
    $("div[data-role='content']").append("<p>" + $(this).find("item").text() + "</p>"); 
    }); 
} 

下面是示例XML:

<?xml version="1.0" encoding="UTF-8"?> 

<recipeml version="0.5"> 
    <recipe> 
    <head> 
     <title>#1 Lemon Bars</title> 
     <categories> 
     <cat>Desserts</cat></categories> 
     <yield>1</yield></head> 
    <ingredients> 
     <ing> 
     <amt> 
      <qty>1 1/2</qty> 
      <unit>cups</unit></amt> 
     <item>All-purpose flour</item></ing> 
     <ing> 
     <amt> 
      <qty>2/3</qty> 
      <unit>cups</unit></amt> 
     <item>Powdered sugar</item></ing> 
     <ing> 
     <amt> 
      <qty>1 1/2</qty> 
      <unit/></amt> 
     <item>Sticks butter; softened</item></ing> 
     <ing> 
     <amt> 
      <qty>3</qty> 
      <unit/></amt> 
     <item>Eggs; lightly beaten</item></ing> 
     <ing> 
     <amt> 
      <qty>1 1/2</qty> 
      <unit>cups</unit></amt> 
     <item>Granulated sugar</item></ing> 
     <ing> 
     <amt> 
      <qty>3</qty> 
      <unit>tablespoons</unit></amt> 
     <item>Flour</item></ing> 
     <ing> 
     <amt> 
      <qty>1/4</qty> 
      <unit>cups</unit></amt> 
     <item>Lemon juice</item></ing> 
     <ing> 
     <amt> 
      <qty/> 
      <unit/></amt> 
     <item>Additional powdered sugar</item></ing></ingredients> 
    <directions> 
     <step> In bowl combine flour, sugar and butter. Pat into 9X13 pan. Bake for 20 
    minutes in a 350F oven. While it is baking, whisk together eggs, 3 TB 
    flour, sugar and lemon juice. Pour over crust while crust is still hot. 
    Bake for an additional 20-25 minutes, or until top is golden brown. Cool on 
    a wire rack and dust with additional powdered sugar. 

    Posted to Bakery-Shoppe Digest V1 #206 by [email protected] (Angela 
    Gilliland) on Aug 29, 1997 

</step></directions></recipe></recipeml> 

,我得到

的XMLHttpRequestç註釋加載文件:/// C:/Users/.../Lemon_Bars.xml。協議方案僅支持交叉源請求:http,data,chrome,chrome-extension,https,chrome-extension-resource。

我知道我無法從其他域加載某些東西,但爲什麼我無法訪問同一文件夾中的文檔?我知道我可以使用JSONP,但有什麼辦法可以使這項工作,或現在是否真的棄用(帖子和教程是4-6歲)。

如果它確實無法工作,那麼用JSONP做到這一點的正確方法是什麼?

回答

0

已解決。

交叉原點請求僅支持協議方案:http,data,chrome,chrome-extension,https,chrome-extension-resource。

我不知道恰好意思,但我的假設是,我要通過HTTP加載文件,所以我就開始XAMPP和加載的文件和它的工作。