如何使用AJAX读取xml文件?

时间:2016-01-08 06:48:33

标签: ajax xml

得到错误,例如“XMLHttpRequest无法加载文件:/// D:/Roshan%20Task/zobble.xml。仅支持协议方案的交叉原始请求:http,数据,chrome,chrome-extension,https,chrome -extension资源“。

$(document).ready(function(){
$('#getQuestion').click(function(){
console.log('i m here');
$.ajax({    
type:"GET", 
url:"zobble.xml",
dataType: "xml",
success:function(xml){          
$(xml).find('question').each(function(){
var Titles = $(this).find('Title').text();
console.log(Titles);    
$("<li></li>").html(Titles ).appendTo("#getQuestion ul");
});     
},  
error:function(){   
console.log('you are out of the xml file');
}
});
});
});

XML文件

<?xml version="1.0" encoding="utf-8" ?>
//name the list of Question (url)
<questions>
//Create three cars
<question>
<Title> Spyder </Title>
</question>
<question>
<Title> M3  </Title>
</question>
<question>
<Title> Gallardo  </Title>
</question>
</questions>

0 个答案:

没有答案