jquery ajax方法不加载文本文件 [英] jquery ajax method is not Loading Text File
问题描述
我正在从w3c school
学习jquery ajax() http:// www。 w3schools.com/jquery/ajax_ajax.asp
I am learning jquery ajax() from w3c school http://www.w3schools.com/jquery/ajax_ajax.asp
我在同一个文件夹中有一个html文件,一个文本文件(demo_test.txt)。点击按钮。 html应该加载文本文件:
I have one html file , 1 text file("demo_test.txt") in same folder. on button click . html should load text file :
这里是代码:
here is code :
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.ajax({url:"demo_test.txt",success:function(result){
$("#div1").html(result);
}});
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
文本文件只有数据this is text file。
Text file only have data "this is text file".
但有些如何不起作用。其他类似的文章没有这种情况..是否有任何问题放置文本文件的物理?请提出建议
But some How it is not working . Other similar post dont have this scenario.. is there any problem placing text file physically ? please suggest
推荐答案
我终于好像得到它的工作。这里是工作脚本
I finally seems to Get it working . Here is working Script
$("button").click(function(){
$.ajax({url:"http://localhost/demo_test.txt",success:function(result){
$("#div1").html(result);
}});
});
解决方法:将html文件和文本文件放在本地服务器(IIS)新网站上。
Workaround : put the html file and text file on local server (IIS) New Site .
这篇关于jquery ajax方法不加载文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!