前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jquery中各个ajax实例操作

jquery中各个ajax实例操作

作者头像
闵开慧
发布2018-03-30 13:57:53
9200
发布2018-03-30 13:57:53
举报
文章被收录于专栏:闵开慧闵开慧
代码语言:javascript
复制
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>jquery_ajax.html</title>
		<script type="text/javascript" src="jquery.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				//jquery.ajax()
				$("#button1").click(function(){
					htmlOjbect = $.ajax({url:"/www.7789.com/testfile/test.php?c=3&t=5", async:false});//不要忘记{}
					$("#getText1").html(htmlOjbect.responseText);
				});

				//ajaxSend()
				$("#sendDiv").ajaxSend(function(e, xhr, opt){
					$(this).html("正在请求……"+opt.url);//此处的url就是下面的load地址
				});
				$("#button2").click(function(){
					$("#getText2").load("/www.7789.com/testfile/test.php?c=2&t=5");
				});

				//get()
				$(".button3").click(function(){
					$.get("/www.7789.com/testfile/test.php?c=5&t=5",function(result){
						$(".getText3").html(result);
					});
				});

				//get() method2
				$(".button4").click(function(){
					$.get("/www.7789.com/testfile/test.php",{c:'2', t:'0'},function(result){
						$(".getText4").html(result);
					});
				});

				//serializeArray()
				$("#formButton").click(function(){
					x = $("form").serializeArray();
					$.each(x, function(i, field){
						$("#results").append(field.name + ":" + field.value + "\t");//里面的name和value分别对应input标签
					});
				});
			});
		</script>
	</head>
	<body>
		<div>
			<button id="button1">ajax异步获取内容</button>
			<div id="getText1"></div>
		</div>

		<div id="sendDiv">
			<button id="button2">ajaxSend异步获取内容</button>
			<div id="getText2"></div>
		</div>

		<div>
			<button class="button3">get异步获取内容1</button>
			<div class="getText3"></div>
		</div>

		<div>
			<button class="button4">get异步获取内容2</button>
			<div class="getText4"></div>
		</div>
		<div>
			<form action="">
				FirstName:<input type="text" name="firstName" value="Bill"/><br/>
				LastName:<input type="text" name="lastName" value="Gates"/><br/>
			</form>
			<button type="button" id="formButton">序列号表单</button>
			<div id="results" value="contents show..."></div>
		</div>

		<div>
			<span id="evalText1"></span>
			<span id="evalText2"></span>
		</div>
		<script type="text/javascript">
		//function eval test
			eval("x=10;y=20;document.write('x*y='+x*y);");
			document.write("<br/>2+12="+eval("2+12"));
			var x=10;
			document.write("<br/>x+17="+eval(x+17));
			//要注意txt里面的格式,很复杂的,最后还要少个‘才能正常运行
			var txt = '{"employees": ['
				+'{"firstName":"Bill","lastName":"Gates"},'
				+'{"firstName":"George","lastName":"Bush"},'
				+'{"firstName":"Thomas","lastName":"Yang"}]}';
			var obj = eval("("+txt+")");
			document.getElementById("evalText1").innerHTML = obj.employees[1].firstName;
			document.getElementById("evalText2").innerHTML = obj.employees[1].lastName;
		</script>
	</body>
</html>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档