AJAX+PHP的简单例子

 <!--
filename:ajax_test.PHP
author:jom_ch
date:06/09/17
mail:phpoop@gmail.com
blog:http://blog.csdn.net/jom_ch
-->
<html>
<head>
<title>Ajax Example of View Picture</title>
<style type="text/css">
<!--
body {
 font-size: 12px;
}
a:link, a:visited, a:active {
 color: #616161;
 text-decoration: none;}
a:hover {
 text-decoration: none;
 background-color: #616161;
 color: #FFFFFF;}
-->
</style>
<script language="javascript">
<!--
function InitAjax(){
  if (window.ActiveXObject) {
   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest) {
   xmlHttp = new XMLHttpRequest();
  }
return xmlHttp;
}
function getPic(pic_id){
  if(typeof(pic_id)=='undefined'){
   return false;
  }
 var url="showPic.php?pic_id="+pic_id;
 var show=document.getElementById("show_Layer");
 var ajax=InitAjax();
 ajax.open("GET",url,true);
 ajax.onreadystatechange=function(){
   if(ajax.readyState==4 && ajax.status==200){
    show.innerHTML=ajax.responseText;
   }
 }
 ajax.send(null);
}
-->
</script>
</head>
<body>
<a href="#" οnclick="getPic(1)">P-1</a>&nbsp;&nbsp;
<a href="#" οnclick="getPic(2)">P-2</a>&nbsp;&nbsp;
<a href="#" οnclick="getPic(3)">P-3</a>&nbsp;&nbsp;
<a href="#" οnclick="getPic(4)">P-4</a>&nbsp;&nbsp;
<br>
<div id="show_Layer"></div>
</body>
</html>

<!--
showPic.php
-->
<?php
echo "<img src='pic_".$_GET[pic_id].".jpg' width=140 border=0>";
?>
同一目录下有pic_1.jpg,pic_2.jpg,pic_3.jpg,pic_4.jpg四个图片,我找了四个britney的小图,效果不错。

补充IFRAME更简单的方法:
<html>
<head>
<title>IFRAME的实现</title>
<script language="javascript">
<!--
function change(num){
 document.change_pic.image.src="../ajax/images/pic_"+num+".jpg";
}
-->
</script>
</head>
<body>
<table border=0 cellpadding=0 cellspacing=0>
 <tr>
  <td><a href='#' οnclick="change(1)">p-1</a></td>
  <td><a href='#' οnclick="change(2)">p-2</a></td>
  <td><a href='#' οnclick="change(3)">p-3</a></td>
  <td><a href='#' οnclick="change(4)">p-4</a></td>
 </tr>
<tr>
 <td colspan=4>
 <Iframe src="iframe_pic_child.htm" name="change_pic" height=300 scrolling="auto" frameborder="0"></iframe>
 </td>
</tr>
</table>
</body>
</html>

<!--iframe_pic_child.htm-->
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<img src="" name="image">
</BODY>
</HTML>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值