加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

第12章 Ajax(上)

发布时间:2020-12-16 01:56:29 所属栏目:百科 来源:网络整理
导读:index.html !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"headmeta http-equiv="Content-Type" content="text/html; charset=utf-8

index.html

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax</title>
<script type="text/javascript" src="jquery-1.10.1.js"></script>
<script type="text/javascript" src="demo.js"></script>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<input type="button" value="异步加载数据" />
<div id="box"></div>
</body>
</html>

test.html

<span class="title">一站式建网站</span>
<span class="url">onestopweb.cn</span>

test.php

<?php
	//echo '一站式建网站';
	/*
	if($_GET['url'] == 'onestopweb'){
		echo '一站式建网站';
	}else{
		echo '不存在';
	}
	if($_POST['url'] == 'onestopweb'){
		echo '一站式建网站';
	}else{
		echo '不存在';
	}
	
	*/
	if($_POST['url'] == 'onestopweb'){
		echo '一站式建网站';
	}else{
		echo '不存在';
	}
?>

demo.js

$(function(){
	/*
	$('input').click(function(){
		$('#box').load('test.html .url');
	});
	$('input').click(function(){
		$('#box').load('test.php');
	});	
	$('input').click(function(){
		$('#box').load('test.php?url=onestopweb');
	});	
	*/
	
	$('input').click(function(){
		$('#box').load('test.php',{
			url : 'onestopweb'
		},function(response,status,xhr){
			//alert(response);
			//$('#box').html(response+'123');
			//alert(status);//打印 success
			//if(status == 'success'){alert('成功后的处理')};
			//alert(xhr.responseText);
			//alert(xhr.responseXML);
			//alert(xhr.status);
			alert(xhr.statusText);
		});
	});	
	
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读