php使用ajax技术

一:html文件(yans.html)

<META http-equiv=content-type content='text/html; charset=utf-8'/>
<META http-equiv=pragma content=no-cache>
<META http-equiv=expires content=0>
</HEAD>
<BODY>
 <input type="button"  name="TEST"  value =" click" onClick="post();">
</BODY>
<script language="javascript" type="text/javascript">
 
 //处理send_request返回信息的函数,使用AJAX时统一调用此函数
 var http,http_return;
 function checkRequest() {
  if (http.readyState==4 && http.status==200) { // 判断对象状态,信息已经成功返回,开始处理信息
   http_return = http.responseText;
  }
 }
 function post()
 {
  try{
   http= new ActiveXObject("Msxml2.XMLHTTP");
  }catch(e)
  {
   try{
    http= new ActiveXObject("Microsoft.XMLHTTP");
   }catch(e)
   {
    alert("create requestHTTP false!");
    return ;
   }
  }
  // escape(),encodeURI();
  http.open("POST","AJax.php?name="+encodeURI("闫生"),true);

  //只有是post提交的时候使用,下面一句话。get不要
  http.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  http.onreadystatechange = checkRequest;

  // 这句话话如果是get提交的话,就发送null即可

 // post提交的时候,相当于提交一个form
  http.send("sex=按钮");
  alert(http_return);
 }
</script>
</HTML>

二:ajax文件(AJax.php)

<?php
function fn_getParam($sSource,$sReplace="")
  {
    $sValue="";
    if (isset($_GET[$sSource])) {
        $sValue = $_GET[$sSource];
    } else if (isset($_POST[$sSource])) {
        $sValue = $_POST[$sSource];
    }
    if (is_null($sValue) || $sValue=="") {
        return $sReplace;
    }
    return $sValue;
  }
$a = fn_getParam('name','yans');
// 打开文件,获得句柄
$handle = fopen('test.txt', 'w+');
// 写入文件
fwrite($handle,$a);

// 关闭文件
fclose($handle);

// 返回ajax操作结果。
echo $a;
?>

转载于:https://www.cnblogs.com/yansheng9988/archive/2008/11/25/1340811.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值