$.ajax({
url:"bianjitran.php",
data:{"id":arr3.id},//前面命名,后面是值
type:"POST",
success: function(s){
try{
這里就出錯了: var s2 =$.base64.decode(s); //進行base64解密
alert(s2); //完全顯示不出來
//以下完全不起作用
arr=JSON.parse(s2);
document.getElementById("xiangmu2").innerText=arr.xiangmu;
document.getElementById("gongjubianhao2").innerText=arr.gongjubianhao;
document.getElementById("wuliaobianma2").innerText=arr.wuliaobianma;
document.getElementById("mingcheng2").innerText=arr.mingcheng;
document.getElementById("guigexinghao2").innerText=arr.guigexinghao;
document.getElementById("danwei2").innerText=arr.danwei;
document.getElementById("yongtu2").innerText=arr.yongtu;
document.getElementById("xuqiushijian2").innerText=arr.xuqiushijian;
document.getElementById("beizhu2").innerText=arr.beizhu;
document.getElementById("shenqingshijian2").innerText=arr.shenqingshijian;
document.getElementById("caigoudanhao2").innerText=arr.caigoudanhao;
document.getElementById("shifoudaohuo2").value=https://bbs.csdn.net/topics/arr.shifoudaohuo;
document.getElementById("cunfangweizhi2").value=https://bbs.csdn.net/topics/arr.cunfangweizhi;
document.getElementById("chukudanhao2").value=https://bbs.csdn.net/topics/arr.chukudanhao;
document.getElementById("daohuoshijian2").value=https://bbs.csdn.net/topics/arr.daohuoshijian;
document.getElementById("id2").value=https://bbs.csdn.net/topics/arr.id;
}
catch(e){
alert(e.name + " :" + e.message );
}
}
});
bianjitran.php代碼為
<?php
$id =$_POST["id"];
$conn=mysql_connect("localhost","root","11111111"); //連接資料庫服務器
mysql_select_db("zonghe",$conn); //連接指定的資料庫
mysql_query("set names utf8"); //對資料庫中的編碼格式進行轉換,避免出現中文亂碼的問題
$result=mysql_query("select * from zonghe2 where id='$id'",$conn);
$row = mysql_fetch_array($result);
$json_arr = array("xiangmu"=>$row['xiangmu'],"gongjubianhao"=>$row['gongjubianhao'],"wuliaobianma"=>$row['wuliaobianma'],"mingcheng"=>$row['mingcheng'],"guigexinghao"=>$row['guigexinghao'],"danwei"=>$row['danwei'],"yongtu"=>$row['yongtu'],"xuqiushijian"=>$row['xuqiushijian'],"beizhu"=>$row['beizhu'],"shenqingshijian"=>$row['shenqingshijian'],"caigoudanhao"=>$row['caigoudanhao'],"shifoudaohuo"=>$row['shifoudaohuo'],"cunfangweizhi"=>$row['cunfangweizhi'],"chukudanhao"=>$row['chukudanhao'],"daohuoshijian"=>$row['daohuoshijian'],"id"=>$row['id']);
$json_obj = json_encode($json_arr); //如果這里就把$json_obj傳回去完全沒問題,OK!
$json_obj2 = base64_encode($json_obj); //傳 $json_obj2,就無法進行解碼,提示undefined
echo $json_obj2;
?>
<?php
mysql_close($conn);
?>
ajax開頭參考了:
<script src="https://bbs.csdn.net/topics/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://bbs.csdn.net/topics/js/jquery.base64.js" type="text/javascript" charset="utf-8"></script>
求大神指導,謝謝!
https://coding.imooc.com/learn/questiondetail/208.html 這里有相同問題,但是看不到,要收錢!
uj5u.com熱心網友回復:
相同問題見:https://coding.imooc.com/learn/questiondetail/208.html第一次提問,求大神多多指導!
uj5u.com熱心網友回復:
我用了笨方法,將出問題的字串搞到id=div2的div里面:eyJ4aWFuZ211IjoiXHU4YmJlXHU2NWJkXHU4YmJlXHU1OTA3IiwiZ29uZ2p1YmlhbmhhbyI6IjEiLCJ3dWxpYW9iaWFubWEiOiIxIiwibWluZ2NoZW5nIjoiMSIsImd1aWdleGluZ2hhbyI6IjEiLCJkYW53ZWkiOiJFQSIsInlvbmd0dSI6IjEiLCJ4dXFpdXNoaWppYW4iOiIxIiwiYmVpemh1IjoiXHU2NWIwXHU1ODllIiwic2hlbnFpbmdzaGlqaWFuIjoiMSIsImNhaWdvdWRhbmhhbyI6IjEiLCJzaGlmb3VkYW9odW8iOiJcdTVkZjJcdTUyMzBcdThkMjciLCJjdW5mYW5nd2VpemhpIjoiMyIsImNodWt1ZGFuaGFvIjoiMiIsImRhb2h1b3NoaWppYW4iOiIxIiwiaWQiOiI4MSJ9
這段字串可以進行64base解碼,完全沒問題,不知問題出在何處?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/119580.html
標籤:Ajax
下一篇:windows server
