最好贴源码,我写程序不知道怎么回事,读都读不出文本的内容 ,代码如下:$(document).ready(function() {
$("#txtconfirm").click(function() {
$.ajax({
url: 'test.txt',
dataType: 'text',
success: function(data) {
alert(data);
}
});
});
});
$("#txtconfirm").click(function() {
$.ajax({
url: 'test.txt',
dataType: 'text',
success: function(data) {
alert(data);
}
});
});
});
初步估计是你的引用jQuery包有问题<html><head>
<title>jQuery Ajax 实例演示</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<script src="http://code.jquery.com/jquery-1.4.3.js"></script>
<body><div id="result" style="background:orange;border:1px solid red;width:300px;height:200px;"></div>
<form id="formtest" action="" method="post">
<span id="success" > </span>
</form>
<script type="text/javascript">$.ajax({
type: "POST",//请求方式
url: "java.txt",//地址,就是action请求路径
data: "text",//数据类型text xml json script jsonp
success: function(msg){//返回的参数就是 action里面所有的有get和set方法的参数
document.getElementById("result").innerHTML=msg;
}
});
</script>
</body>
</html>
$("#txtconfirm").click(function() { //id=txtconfirm的元素是否存在
$.ajax({
url: 'test.txt', // url路径是否正确
dataType: 'text',
success: function(data) {
alert(data);
}
});
});
});
<head>
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>
<script>
$(document).ready(function() {
$("#txtconfirm").click(function(){
$.ajax({
url: 'test.txt',
dataType: 'text',
error: function(xhr) { alert( xhr.responseText ); }, //如果你的url,txt有问题,将会提示
success: function(data) {
alert(data);
}
});
});
});
</script>
</head><body>
<div id="txtconfirm">sss</div> ---id要正确
</body>
</html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
.<title></title> <script type="text/javascript" src="Default2_files/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#txtconfirm").click(function() { $.ajax({ url: 'test.txt', dataType: 'text', error: function(xhr) { alert(xhr.responseText); }, success: function(data) { alert(data);
}
});
});
});
</script> <div>
<input style="width: 200px;" id="txtContent" type="text"><input id="txtconfirm" value="确定"
type="button"></div>
</body>
</html>
路径没错
$(document).ready(function() {
$("#txtconfirm").click(function() {
$.ajax({
url: 'test.txt',
dataType: 'text',
error: function(xhr) { alert("error: " + xhr.responseText); },
success: function(data) {
alert("success: " + data);
}
});
});
});
</script>如果是"succcess: ", 看txt文件内容是否为空。