php jQuery json 你呀的你怎么就传不回来呢?晕,原来这样,,,处理回调的文件一定不能有htm静态文本

来源:互联网 发布:变则腰振r18动作数据 编辑:程序博客网 时间:2024/05/16 17:39

今天同网站内的写并回调出来最新的数据,也就是无刷新改写,这个以前写过,很简单,,,于是,,,写,然后,,,,改写,,,,然后仿写,,,,然后,,,百度,,,,然后怎么还是数据能post出去,回不来呢!

这!,,,,,我,,,,无解了,,,,,,,,使用代码能传出去!怎么就回不来!!!回不来!!!最后还是搞不下去睡觉了,第二天起来发现,原来回调处理的php文件也就是第二个文件,一定不能有头部文件也就是直接输出json格式,不要带上什么head body之类的静态语言!第二个直接输出json不要多此一举。新建文件的先删除所有文本,然后写回调数据的php代码!就可以了,,,,

t1.php

<!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>无标题文档</title><!--<script type="text/javascript" src="xiaoyu/memb/include/jquery-1.5.2.min.js"></script>--><script type="text/javascript" src="../../../../../jquery-1.8.3.js"></script></head><body><!-- 例如: $("a").click(function(e) {               e.preventDefault();--><script>$(document).ready(function(e) {//$(document).ready(function(){  // 在这里写你的代码...  //获取焦点  $("#a1").focusin(function() {  var fpas_answ="atta";  //alert("focusin is ok!");  $("#fpas_answ_chk__1").html("abc");  chk_reg_fpas_answ(fpas_answ);   });function chk_reg_fpas_answ(fpas_answ){$.ajax({    type: "post",     url : "./t_ajax.php",    dataType:'json',data: 'fpas_answ='+fpas_answ,    success: function(json){alert(json.fpas_answ_chk__1);$("#fpas_answ_chk__1").html(json.fpas_answ_chk__1);//ok,err,pic$("#fpas_answ_chk__2").html(json.fpas_answ_chk__2);//string read$("#fpas_answ_chk__3").html(json.fpas_answ_chk__3);//status ok,err                          }             });}
});</script><table width="200" border="1">  <tr>    <td id="a1">&nbsp;</td>    <td id="a2">&nbsp;</td>    <td id="a3">&nbsp;</td>  </tr>  <tr>    <td id="fpas_answ_chk__1">&nbsp;</td>    <td id="fpas_answ_chk__2">&nbsp;</td>    <td id="fpas_answ_chk__3">&nbsp;</td>  </tr>  <tr>    <td>&nbsp;</td>    <td>&nbsp;</td>    <td>&nbsp;</td>  </tr></table></body></html>

t_ajax.php
<?php

//新建文件的时候一定要把该死的html的所有清空,然后直接写php的代码,要不,,,折腾吧,反正没输出。
if(isset($_POST["fpas_answ"])){
$fp1=fopen("tmp1.txt","wb");
fwrite($fp1,$_POST["fpas_answ"]."\n");
fclose($fp1);
}

echo json_encode(array('fpas_answ_chk__1'=>'test11','fpas_answ_chk__2'=>'test22','fpas_answ_chk__3'=>'test33'));

?>



0 0
原创粉丝点击