0

这是 chrome 浏览器抛出的消息错误,它在 IExplorer 和 FireFox 中运行良好

$ XMLHttpRequest cannot load file:///C:/Users/Lew/Documents/Human%20Staff/students.xml. Origin null is not allowed by Access-Control-Allow-Origin.

....如果已经定义了变量,我不知道为什么它不起作用...

chrome开发者工具抛出的另一个错误消息:

$nombre: [Exception: ReferenceError: telefono is not defined]
$edad : [Exception: ReferenceError: telefono is not defined]
$telefono : [Exception: ReferenceError: telefono is not defined]
$carnet : [Exception: ReferenceError: telefono is not defined]

有什么想法可以解决吗?

这是一段代码:

<pre><code>

    // JavaScript Document
    // File: leerXML.js


   $(document).ready(function(){


   $("#ContentArea").ready(function(){
   $.get("students.xml",{},function(xml){ //Abrimos el archivo students.xml

// Crearemos un string HTML
    HTMLcontent = '<br/><br/>';
    HTMLcontent += '<table width="70%" border="1" cellpadding="0" cellspacing="0">';
    HTMLcontent += '<th>Nombre</th><th>Edad</th><th>Telefono</th><th>Carnet</th>';

   $('estudiante',xml).each(function(i) {

   var nombre ='';
   var edad='';
   var telefono='';
   var carnet='';
   nombre = $(this).find("nombre").text(); 
   edad = $(this).find("edade").text();
   telefono = $(this).find("telefono").text();
   carnet = $(this).find("carnet").text();

4

1 回答 1

0

您不能这样做,因为您是从本地文件系统加载网站。您需要运行 Web 服务器才能进行跨域请求(文件系统的来源为 null,因为它没有域,并且永远不允许发出跨域请求)。

设置一个小型 Web 服务器并从中提供文件以进行测试。请参阅http://code.google.com/p/chromium/issues/detail?id=40787

于 2012-10-18T02:29:42.147 回答