jquery-ajax的用法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>jq-1</title>
	<style>
	#info{ border: 1px solid red; width: 100px;}
	</style>
	<script src="http://www.w3school.com.cn/jquery/jquery.js"></script>
	<script>
	$(function (){
		//alert($("#info").html());
		$("#info").click(function (){
			$.ajax({
				url:"./ajax1.txt",	//url请求的地址
				beforeSend:beforeSend2,	//发送之前执行的操作
				error:error2,	//发生错误时候执行
				success:success2,	//成功时执行
				datatype: 'text'	//接受从服务器返回的数据类型	xml、html、script、json、jsonp、text.
			});			
		});
		function beforeSend2(){
			alert("这里是beforeSend");
		}
		function error2(){
			alert("出错的error在这里");
		}
		function success2(data){
			alert(data);
			$("#info2").html(data);
		}
	});
	</script>
</head>
<body>
	<div id="info">info</div>
	<div id="info2"></div>
</body>
</html>

  


  • dataType的类型

  • ajax是向服务器请求数据
  • No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.  跨域
    •   在服务器上运行ajax的请求。

 

 

posted @ 2014-04-26 11:33  半颠者  阅读(237)  评论(0编辑  收藏  举报