3
$(document).ready(function(){       // load jQuery 1.5
  function loadfail(){
  alert("Error: Failed to read file!");
 }

 function parse(document){
 $(document).find("el").each(function(){
    var optionLabel = $(this).find('text').text();
    var optionValue = $(this).find('value').text();
    $('#el').append(
   '<option value="'+ optionValue + '">' + optionLabel + '</option>'
    );
 });
 }

 $.ajax({
  url: "ednlevel.xml",    // name of file with our data - link has been renamed
  dataType: 'xml',    // type of file we will be reading
  success: parse,     // name of function to call when done reading file
  error: loadfail     // name of function to call when failed to read
 });
});

The above code works fine with Firefox but it isn't working on chrome or Internet Explorer. What is wrong with it?

Deep
  • 830
  • 7
  • 21

1 Answers1

0

By default, on local, chrome and IE not working with ajax request. (same origin error).

Please try to put your file directly on server. Or active adequate header (Access-Control-Allow-Origin) on your local server.

And add content-type and send request parameter:

$.ajax({
        type:"get",
        url: "ednlevel.xml",    // name of file with our data - link has been renamed
        dataType: 'xml',    // type of file we will be reading
        contentType: "text/xml",
        success: parse,     // name of function to call when done reading file
        error: loadfail     // name of function to call when failed to read
    });

You can can find more information here : jQuery xml error ' No 'Access-Control-Allow-Origin' header is present on the requested resource.'

Community
  • 1
  • 1
P. Frank
  • 5,505
  • 5
  • 19
  • 47