简体   繁体   中英

The w3schools.com example for ajax file read from server works in IE9 but not FF12

I need to read the contents of a text file from the server and parse the contents with JavaScript, in order to add elements to the page depending on the contents.

But, the example at W3Schools works great in FF12 but if I copy the source from the left-pane of the example to an .html file, and create the required data file "demo_ajax_load.txt" in the same directory as my .html, it doesn't work. However, it works okay in IE9.

Here's the source:

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $.get("demo_ajax_load.txt", function(result){
      $("div").html(result);
    });
  });
});
</script>
</head>
<body>

<div><h2>Let AJAX change this text</h2></div>
<button>Change Content</button>

</body>
</html>

使用vxworks而不是Windows解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM