87,904
社区成员
发帖
与我相关
我的任务
分享
$(document).ready(function() {
$("#txtconfirm").click(function() {
$.ajax({
url: 'test.txt',
dataType: 'text',
success: function(data) {
alert(data);
}
});
});
});
<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>
路径没错
<html>
<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>
<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>