Home > front end >  Why return through ajax PHP base64 (json string) unable to decode? Prompt error is undefined
Why return through ajax PHP base64 (json string) unable to decode? Prompt error is undefined

Time:10-09

$. Ajax ({
Url: "bianjitran. PHP,"
Data: {" id ": arr3. Id},//in front of the name, followed by a value
Type: "POST",

Success: the function (s) {
Try {


Here is wrong: var s2=$base64. Decode (s);//base64 decryption
Alert (s2);//completely could not show

//the following completely ineffective
Arr=JSON. Parse (s2);
Document. The getElementById (" xiangmu2 "). The innerText=arr. Xiangmu;
Document. The getElementById (" gongjubianhao2 "). The innerText=arr. Gongjubianhao;
Document. The getElementById (" wuliaobianma2 "). The innerText=arr. Wuliaobianma;
Document. The getElementById (" mingcheng2 "). The innerText=arr. Mingcheng;
Document. The getElementById (" guigexinghao2 "). The innerText=arr. Guigexinghao;
Document. The getElementById (" danwei2 "). The innerText=arr. Danwei;
Document. The getElementById (" yongtu2 "). The innerText=arr. Yongtu;
Document. The getElementById (" xuqiushijian2 "). The innerText=arr. Xuqiushijian;
Document. The getElementById (" beizhu2 "). The innerText=arr. Beizhu;
Document. The getElementById (" shenqingshijian2 "). The innerText=arr. Shenqingshijian;
Document. The getElementById (" caigoudanhao2 "). The innerText=arr. Caigoudanhao;
Document. The getElementById (" shifoudaohuo2 "). value=https://bbs.csdn.net/topics/arr.shifoudaohuo;
Document. The getElementById (" cunfangweizhi2 "). value=https://bbs.csdn.net/topics/arr.cunfangweizhi;
Document. The getElementById (" chukudanhao2 "). value=https://bbs.csdn.net/topics/arr.chukudanhao;
Document. The getElementById (" daohuoshijian2 "). value=https://bbs.csdn.net/topics/arr.daohuoshijian;
Document. The getElementById (" id2 "). value=https://bbs.csdn.net/topics/arr.id;

}
The catch (e) {
Alert (e.n ame + ":" + e.m essage);

}

}


});

Bianjitran. PHP code for

<? PHP
$id=$_POST (" id ");

$conn=mysql_connect (" localhost ", "root", "11111111");//connect to the database server
The mysql_select_db (zonghe, $conn);//connection specified database
Mysql_query (" set names utf8 ");//the coding format conversion in the database, avoid the problem of Chinese garbled
$result=mysql_query (" select * from zonghe2 where id='$id ", $conn);
$row=mysql_fetch_array ($result);
$json_arr=array (" xiangmu=& gt;" $row [' xiangmu], "gongjubianhao=& gt;" $row [' gongjubianhao], "wuliaobianma=& gt;" $row [' wuliaobianma], "mingcheng=& gt;" $row [' mingcheng], "guigexinghao=& gt;" $row [' guigexinghao], "danwei"=& gt; $row [" danwei "], "yongtu=& gt;" $row [' yongtu], "xuqiushijian=& gt;" $row [' xuqiushijian], "beizhu=& gt;" $row [' beizhu], "shenqingshijian=& gt;" $row [' shenqingshijian], "caigoudanhao=& gt;" $row [' caigoudanhao], "shifoudaohuo=& gt;" $row [' shifoudaohuo], "cunfangweizhi=& gt;" $row [' cunfangweizhi], "chukudanhao=& gt;" $row [' chukudanhao], "daohuoshijian=& gt;" $row [' daohuoshijian], "id=" & gt; $row [' id ']);
$json_obj=json_encode ($json_arr); //pass $json_obj back to full if there will be all right, OK!
$json_obj2=base64_encode ($json_obj); //$json_obj2, will not be able to decode, prompt undefined
Echo $json_obj2;

?>


<? PHP

Mysql_close ($conn);
?>

Ajax start quote:
<script SRC="https://bbs.csdn.net/topics/js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/js/jquery.base64.js" type="text/javascript" charset="utf-8" & gt; </script>

The great spirit guide, thank you!
https://coding.imooc.com/learn/questiondetail/208.html has the same problem here, but can't see, take money!

CodePudding user response:

See the same problem: https://coding.imooc.com/learn/questiondetail/208.html

For the first time to ask questions, the great god a lot of guidance!

CodePudding user response:

I use the stupid method, strings that will be a problem to the div id=div2:

EyJ4aWFuZ211IjoiXHU4YmJlXHU2NWJkXHU4YmJlXHU1OTA3IiwiZ29uZ2p1YmlhbmhhbyI6IjEiLCJ3dWxpYW9iaWFubWEiOiIxIiwibWluZ2NoZW5nIjoiMSIsImd1aWdleGluZ2hhbyI6IjEiLCJkYW53ZWkiOiJFQSIsInlvbmd0dSI6IjEiLCJ4dXFpdXNoaWppYW4iOiIxIiwiYmVpemh1IjoiXHU2NWIwXHU1ODllIiwic2hlbnFpbmdzaGlqaWFuIjoiMSIsImNhaWdvdWRhbmhhbyI6IjEiLCJzaGlmb3VkYW9odW8iOiJcdTVkZjJcdTUyMzBcdThkMjciLCJjdW5mYW5nd2VpemhpIjoiMyIsImNodWt1ZGFuaGFvIjoiMiIsImRhb2h1b3NoaWppYW4iOiIxIiwiaWQiOiI4MSJ9

This piece of string to the base 64 decoding, completely no problem, I don't know where the problem?
  •  Tags:  
  • Ajax
  • Related