Table of Contents
回复讨论(解决方案)
安全信息
Home Backend Development PHP Tutorial die(json_encode(. 没返回

die(json_encode(. 没返回

Jun 23, 2016 pm 01:47 PM

我的ajax代码

$.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) { alert("ok");	...
Copy after login


php代码:
tip("100", '<font color="red">交易密码不能与登录密码一样!</font>');
Copy after login


function tip($code, $msg) {    $arr['code'] = iconv('GB2312', 'UTF-8', $code);    $arr['msg'] = iconv('GB2312', 'UTF-8', $msg);	    //die(json_encode($arr));    die(var_json_encode($arr));  //cjq}function var_json_encode($var){  $_var = var_urlencode($var);  $_str = json_encode($_var);  return urldecode($_str); }
Copy after login


结果页面没有弹出那个alert("ok"),说明ajax没返回?

改成这样也不行:
function tip($code, $msg) {    $arr['code'] = iconv('GB2312', 'UTF-8', $code);    $arr['msg'] = iconv('GB2312', 'UTF-8', $msg);	    die(json_encode($arr,JSON_UNESCAPED_UNICODE));  //cjq}
Copy after login


这是为什么呢?


回复讨论(解决方案)

这样也不行:(

function tip($code, $msg) {    $arr['code'] = $code;    $arr['msg'] = $msg;    die(json_encode($arr,JSON_UNESCAPED_UNICODE));  //cjq}
Copy after login

$_var = var_urlencode($var);
这个函数是在哪里定义的?

$_var = var_urlencode($var);
这个函数是在哪里定义的?



/** * 对变量或者数据进行 urlencode 编码, 使得在进行 json_encode 的时候进行编码的不是中文, 防 止 json_encode 失败 * @access private * @param $var * @return array */ function var_urlencode($var) { if (empty ( $var )) { return false; } if (is_array ( $var )) { foreach ( $var as $k => $v ) { if (is_scalar ( $v )) {//if 用来处理不是数组的情况 $var [$k] = urlencode ( $v ); } else {//else 用来处理数组 $var [$k] = var_urlencode ( $v ); } } } else {//用来处理数组 $var = urlencode ( $var ); } return $var; } 
Copy after login

输出 utf-8 编码的
{"code":"100","msg":"交易密码不能与登录密码一样!"}

应该是其他方面的问题
你在浏览器中查看源文件检查一下

输出 utf-8 编码的
{"code":"100","msg":"交易密码不能与登录密码一样!"}
应该是其他方面的问题
你在浏览器中查看源文件检查一下



页面源代码:
...<div class="aqxx_con">           <div class="aqxx_header_con">        <ul>          <li class="aqxx_neixing">交易密码</li>          <li class="aqxx_zhuangtai">为了您的账户安全,提现需要输入交易密码,请确保与登录密码不同。</li>          <li class="aqxx_last">          <a href="javascript:void(0);" id="txshow1" class="jrb_but03">设置</a><a href="javascript:void(0);" id="txhide1" style="display:none" class="jrb_but03">取消设置</a>         </li>        </ul>      </div>            <div class="aqxx_con_xq" id="jiaoyimima02" style="display:none"><iframe src="/safeinfo-jiaoyimima.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="200px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>      <div class="aqxx_con_xq" id="jiaoyimima03" style="display:none"><iframe src="/safeinfo-jiaoyimima03.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="270px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>       <div class="aqxx_con_xq" id="jiaoyimima04" style="display:none"><iframe src="/safeinfo-jiaoyimima04.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="150px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>            <div class="aqxx_header_con" id="findpass" style="display:none">      <ul>          <li class="aqxx_neixing"> </li>          <li class="aqxx_zhuangtai"> </li>          <li class="aqxx_last">         <a href="javascript:void(0);" id="zhshow" class="jrb_but03">找回密码</a><a href="javascript:void(0);" id="zhhide" style="display:none" class="jrb_but03">取消找回</a>         </li>      </ul>      </div>          </div>...
Copy after login


当前页面显示的是safeinfo-jiaoyimima.html的内容,
safeinfo-jiaoyimima.html的内容如下:

<!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><link href="__PUBLIC__/frontend/css/user.css" rel="stylesheet" type="text/css" /><link href="__PUBLIC__/frontend/css/base.css" rel="stylesheet" type="text/css" /><script src="__PUBLIC__/frontend/js/jquery.js" type="text/javascript"></script>        <style type="text/css">.wsz {	color:#a9a9a9}.sz {	color:#CCCCD5;}.smyz {	color:#a9a9a9;	display:none}.tscg {	display:none}</style></head><body style="background:#FFF"><div class="aq_iframe">  <form action="{:U('Safeinfo/txpassadd')}" method="post" id="txadd">        <p>          <label for="username"><span style="color:#F00; margin-right:5px;">*</span>交易密码</label>          <input type="password" class="aqifm_srk" name="txpass" placeholder="6-12位字母、数字、符号"/>          <span class="tip_aq">          <font class="smyz txpass">交易密码不能为空!</font>          <font class="tscg4"></font>          </span>        <p>          <label for="username"><span style="color:#F00; margin-right:5px;">*</span>重复密码</label>          <input type="password" class="aqifm_srk" name="rtxpass" placeholder="请再次输入您的交易密码"/>          <span class="tip_aq">          <font class="smyz rtxpass">重复密码不能为空!</font>          </span>        <div class="aqifm_con_but">          <input name="" type="button" value="提  交" class="jrb_but02" id="txaj"/>        </div>          </form></div><script>//提现密码添加    $("#txaj").click(function() {        if ($("input[name='txpass']").val() == "") {            $(".txpass").show();        } else {            $(".txpass").hide();        }        if ($("input[name='rtxpass']").val() == "") {            $(".rtxpass").show();        } else {            $(".rtxpass").hide();        }        if ($("input[name='txpass']").val() != "" && $("input[name='rtxpass']").val() != "" && txpass()) {                    alert("ok1");				            $.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) {                    alert("ok2");							             var data1=eval("("+data+")"); 			                 $(".tscg4").html(data1.msg);				 					//cjq script                    //alert("data.code: " + data.code);					                 if (data1.code === '10000') {                    setTimeout(function() {                       parent.location.reload();                    }, 1000);                }             },'json');        }    })	//判断添加提现密码长度function txpass() {    if ($("input[name='txpass']").val().length > 5 && $("input[name='txpass']").val().length < 13) {        return true;    } else {        $(".tscg4").html("<font color=\"#a9a9a9\">密码必须要6-12位字母、数字和符号!</font>");        return false;    }}</script></body></html>
Copy after login


怎么改代码都是只弹出了alert("ok1"); 没有弹出alert("ok2"); 郁闷了几天了!请指教,谢谢!

我要你看的是:
模板中的 $.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) {
在浏览器源码中是什么?

我要你看的是:
模板中的 $.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) {
在浏览器源码中是什么?



我查看当前页面源代码就是楼上的第一段代码,但我不知道怎么在firefox中查看模板中的 $.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) { 在浏览器的源码。

百思不得其解,困惑啊!

师者,所以传道、授业、解惑也,谁是我的老师呢?

你为什么要省略在浏览器中看到的代码呢?

$.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) { alert("ok");	...},"json");
Copy after login

jquery里指明返回参数类型

你为什么要省略在浏览器中看到的代码呢?



        <head>        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>安全设置 - 桂林金融宝众投借贷平台</title><!--[if IE 6]><script src="/Public/frontend/js/DD_belatedPNG.js"></script><script>  /* EXAMPLE */  DD_belatedPNG.fix('.png_fix');</script> <style type="text/css">.smyz {	color:#a9a9a9;	display:none}.tscg {	display:none}</style>        </head>        <body><div class="div1"><div class="zhutineirong">     <div class="left">        <div class="first"><img  class="png_fix lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/home.png"      style="max-width:90%"  style="max-width:90%"  title="我的巨轮贷"/ alt="die(json_encode(. 没返回" ><a href="/usercontent-index.html">我的巨轮贷</a></div>        <ul class="left_navi">   	            <li class="zj "><img  class="png_fix lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/005.png"      style="max-width:90%"  style="max-width:90%"  title="资金管理"/ alt="die(json_encode(. 没返回" ><img  class="img1 lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/005_2.png"      style="max-width:90%"  style="max-width:90%"   title="资金管理"/ alt="die(json_encode(. 没返回" ><span class="zj">资金管理</span>                <dl class="zjxl"  >                     <dt >                     <dd ><a href="/charge-show.html">充值</a></dd>                    <dd ><a href="/withdraw-show.html">提现</a></dd>                    <dd ><a href="/capital-index.html">交易记录</a></dd>                           </dt>                                </dl>             </li>            <li class="zj "><img  class="png_fix lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/062.png"      style="max-width:90%"  style="max-width:90%"  title="投资管理"/ alt="die(json_encode(. 没返回" ><img  class="img1 lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/062_1.png"      style="max-width:90%"  style="max-width:90%"   title="投资管理"/ alt="die(json_encode(. 没返回" ><span class="zj">投资管理</span>                <dl class="zjxl" >                      <dt>                     <dd ><a href="/invest-index.html">我的投资</a></dd>                    <dd ><a href="/invest-statistics.html">投资统计</a></dd>                    </dt>                </dl>            </li>            <li class="zj "><img  class="png_fix lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/009.png"      style="max-width:90%"  style="max-width:90%"  title="借贷管理"/ alt="die(json_encode(. 没返回" ><img  class="img1 lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/009_2.png"      style="max-width:90%"  style="max-width:90%"  title="借贷管理"/ alt="die(json_encode(. 没返回" ><span class="zj">借贷管理</span>                <dl class="zjxl" >                     <dt>                     <dd ><a href="/loan-findAll.html" class="ok">我的借款</a></dd>                    <dd ><a href="/loan_total-index.html">借款统计</a></dd>                    </dt>                                </dl>            </li>            <li class="zj  cur"><img  class="png_fix lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/011.png"      style="max-width:90%"  style="max-width:90%"  title="账户管理"/ alt="die(json_encode(. 没返回" ><img  class="img1 lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/011_1.png"      style="max-width:90%"  style="max-width:90%"  title="账户管理"/ alt="die(json_encode(. 没返回" ><span class="zj">账户管理</span>                <dl class="zjxl"  style="display: block">                     <dt>                     <dd ><a href="/userinfo-index.html">个人资料中心</a></dd>                    <dd class="d-cur"><a href="/safeinfo-index.html" class="ok">安全设置</a></dd>                    <dd ><a href="/account-bankCard.html">银行卡设置</a></dd>                    <dd ><a href="/authhome-index.html">申请认证</a></dd>                    </dt>                                </dl>            </li>            <li class="zj "><img  class="png_fix lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/022.png"      style="max-width:90%"  style="max-width:90%"  title="互动管理"/ alt="die(json_encode(. 没返回" ><img  class="img1 lazy"  src="/static/imghw/default1.png"  data-src="/Public/frontend/images/ico/022_1.png"      style="max-width:90%"  style="max-width:90%"  title="互动管理"/ alt="die(json_encode(. 没返回" ><span class="zj">互动管理</span>                <dl class="zjxl" >                     <dt>                     <dd ><a href="/msg-index.html">站内消息</a></dd>                    </dt>                                </dl>            </li>        </ul>    </div>           <div class="users_right_con">    <h1 id="安全信息">安全信息</h1>    <div class="aqxx_con">      <div class="aqxx_header_con">        <ul>          <li class="aqxx_neixing">登录密码</li>          <li class="aqxx_zhuangtai">为了您的账户安全,请定期更换登录密码,并确保与交易密码不同。</li>          <li class="aqxx_last" id="denglumima">          <a href="javascript:void(0);" id="clokshow" class="jrb_but03">修改</a><a href="javascript:void(0);" id="clokhide" style="display:none" class="jrb_but03">取消修改</a>         </li>        </ul>      </div>      <div class="aqxx_con_xq" id="denglumima02" style="display:none"><iframe src="/safeinfo-denglumima.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="270px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>    </div>    <div class="aqxx_con">           <div class="aqxx_header_con">        <ul>          <li class="aqxx_neixing">交易密码</li>          <li class="aqxx_zhuangtai">为了您的账户安全,提现需要输入交易密码,请确保与登录密码不同。</li>          <li class="aqxx_last">          <a href="javascript:void(0);" id="txshow1" class="jrb_but03">设置</a><a href="javascript:void(0);" id="txhide1" style="display:none" class="jrb_but03">取消设置</a>         </li>        </ul>      </div>            <div class="aqxx_con_xq" id="jiaoyimima02" style="display:none"><iframe src="/safeinfo-jiaoyimima.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="200px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>      <div class="aqxx_con_xq" id="jiaoyimima03" style="display:none"><iframe src="/safeinfo-jiaoyimima03.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="270px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>       <div class="aqxx_con_xq" id="jiaoyimima04" style="display:none"><iframe src="/safeinfo-jiaoyimima04.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="150px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>            <div class="aqxx_header_con" id="findpass" style="display:none">      <ul>          <li class="aqxx_neixing"> </li>          <li class="aqxx_zhuangtai"> </li>          <li class="aqxx_last">         <a href="javascript:void(0);" id="zhshow" class="jrb_but03">找回密码</a><a href="javascript:void(0);" id="zhhide" style="display:none" class="jrb_but03">取消找回</a>         </li>      </ul>      </div>          </div>    <div class="aqxx_con">           <div class="aqxx_header_con">        <ul>          <li class="aqxx_neixing">绑定邮箱</li>          <li class="aqxx_zhuangtai">mic****ah.net</li>          <li class="aqxx_last">         <a style="color:#999; margin-right:10px;">已验证</a>        </li>        </ul>      </div>            <div class="aqxx_con_xq" id="bangdingyouxiang02" style="display:none"><iframe src="/safeinfo-bangdingyouxiang.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="150px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>    </div>    <div class="aqxx_con">               <div class="aqxx_header_con">        <ul>          <li class="aqxx_neixing">绑定手机</li>          <li class="aqxx_zhuangtai">可以用手机找回您的密码,更改手机请先验证。</li>          <li class="aqxx_last">          <a href="javascript:void(0);" id="phoneshow1" class="jrb_but03">修改</a><a href="javascript:void(0);" id="phonehide1" style="display:none" class="jrb_but03">取消修改</a>         </li>        </ul>      </div>                  <div class="aqxx_con_xq" id="bangdingshouji02" style="display:none"><iframe src="/safeinfo-bangdingshouji.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="200px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>       <div class="aqxx_con_xq" id="bangdingshouji03" style="display:none"><iframe src="/safeinfo-bangdingshouji03.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="270px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>        <div class="aqxx_con_xq" id="bangdingshouji04" style="display:none"><iframe src="/safeinfo-bangdingshouji04.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="200px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>    </div>    <!--    <div class="aqxx_con">           <div class="aqxx_header_con">        <ul>          <li class="aqxx_neixing">实名认证</li>          <li class="aqxx_zhuangtai">45****************</li>          <li class="aqxx_last">         <label class="sz"> 周*****</label>        </li>        </ul>      </div>                    <div class="aqxx_con_xq" id="shimingrenzheng02" style="display:none"><iframe src="/safeinfo-shimingrenzheng.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="200px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe></div>    </div>    -->  </div>       </div><script src="/Public/frontend/js/jquery.js" type="text/javascript"></script><script type="text/javascript">    var env = 0;    $(document).ready(function() {        $(".zj dd").click(function() {            env = 1;        });        $(".zj").click(function() {            if (env === 0) {                $(this).children(".zjxl").toggle();            }            env = 0;        });        $('.verify-code').addClass('.verify-code');       });</script></div> <script src="/Public/frontend/js/anquan.js" language="javascript"></script><script>        $(document).ready(function() {            $("#denglumima").click(function() {                $("#denglumima02").toggle();            })			$("#jiaoyimima").click(function() {                $("#jiaoyimima02").toggle();            })			$("#bangdingyouxiang").click(function() {                $("#bangdingyouxiang02").toggle();            })		        });</script></body></html> 
Copy after login


这是全部代码,谢谢!

你这个对吗?
既没有看到 id=txadd 的标记,已没有看到 $.post(.... 代码

你这个对吗?
既没有看到 id=txadd 的标记,已没有看到 $.post(.... 代码



这些代码在 safeinfo-jiaoyimima.html 里,safeinfo-jiaoyimima.html的代码在5楼下半部分。
请注意楼上代码里的这段代码:
<iframe src="/safeinfo-bangdingshouji.html" style="marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="400px" height="200px"" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');"></iframe>
Copy after login

既然是在框架里,那你就贴出框架里看到的 html 代码
#5 的只是模板文件,如果是直接使用肯定是不行的

既然是在框架里,那你就贴出框架里看到的 html 代码
#5 的只是模板文件,如果是直接使用肯定是不行的



看到的框架代码是:
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">.smyz {	color:#a9a9a9;	display:none}.tscg {	display:none}</style></head><body style="background:#FFF"><div class="aq_iframe">  <form action="/safeinfo-txpassadd.html" method="post" id="txadd">        <p>          <label for="username"><span style="color:#F00; margin-right:5px;">*</span>交易密码</label>          <input type="password" class="aqifm_srk" name="txpass" placeholder="6-12位字母、数字、符号"/>          <span class="tip_aq">          <font class="smyz txpass">交易密码不能为空!</font>          <font class="tscg4"></font>          </span>        <p>          <label for="username"><span style="color:#F00; margin-right:5px;">*</span>重复密码</label>          <input type="password" class="aqifm_srk" name="rtxpass" placeholder="请再次输入您的交易密码"/>          <span class="tip_aq">          <font class="smyz rtxpass">重复密码不能为空!</font>          </span>        <div class="aqifm_con_but">          <input name="" type="button" value="提  交" class="jrb_but02" id="txaj"/>        </div>          </form></div><script>//提现密码添加    $("#txaj").click(function() {        if ($("input[name='txpass']").val() == "") {            $(".txpass").show();        } else {            $(".txpass").hide();        }        if ($("input[name='rtxpass']").val() == "") {            $(".rtxpass").show();        } else {            $(".rtxpass").hide();        }        if ($("input[name='txpass']").val() != "" && $("input[name='rtxpass']").val() != "" && txpass()) {			//cjq script                    alert("ok1");						            $.post('/safeinfo-txpassadd.html', $("#txadd").serialize(), function(data) {			//cjq script                    alert("ok2");							             var data1=eval("("+data+")"); 			                 $(".tscg4").html(data1.msg);				 					//cjq script                    //alert("data.code: " + data.code);					                 if (data1.code === '10000') {                    setTimeout(function() {                       parent.location.reload();                    }, 1000);                }             },'json');        }    })	//判断添加提现密码长度function txpass() {    if ($("input[name='txpass']").val().length > 5 && $("input[name='txpass']").val().length < 13) {        return true;    } else {        $(".tscg4").html("<font color=\"#a9a9a9\">密码必须要6-12位字母、数字和符号!</font>");        return false;    }}</script></body></html>  
Copy after login

敬爱的@xuzuning 老师,您好,怎么没下文啦?

点击提交,只弹出了alert("ok1"); 没有弹出alert("ok2"); 这到底是为什么呢?

safeinfo-txpassadd.html 代码?

safeinfo-txpassadd.html 代码?



谢谢回复!没有这个文件,只有SafeinfoAction.class.php:
class SafeinfoAction extends BaseAction {    public function _initialize() {        parent::_initialize();        $this->time = $_SESSION['e_time'];        $webData = M('web')->where('id=1')->find();        $this->meta = array(            'title' => '安全设置 - ' . $webData['webtitle'],            'keywords' => '安全设置|' . $webData['webkeyword'],            'description' => strip_tags($webData['new_notice']),        );    }    const EXPIRED_TIME = 120;    //显示安全信息页面    public function index() {        import('@.ORG.String');        $user = M("user_info");        $user1 = M("user");        $auth = M('auth_info');        $list = $user->where("uid=" . $_SESSION["uid"])->find();        $list1 = $user1->where("id=" . $_SESSION["uid"])->find();        $data['uid'] = $_SESSION['uid'];        $data['auth_type'] = 1;        $list2 = $auth->where($data)->find();        $this->AS["user"] = $list;        $this->AS["user1"] = $list1;        $this->AS["user2"] = $list2;        $this->assign($this->AS);        $this->display();    }    //提现密码添加    public function txpassadd() {         $user = M('user');        if (I('txpass') == "" || I('rtxpass') == "") {            tip('100', '请输入完整信息');        }        if (I('txpass') != I('rtxpass')) {            tip("3", '两次输入的密码不一致!');        }        $map['id'] = $this->uid;        $u = $user->where($map)->find();        if (empty($u)) {            tip("100", '未知用户!');        }        $data['u_trade_password'] = I('rtxpass', '', 'fix_pass');        if ($data['u_trade_password'] == $u['u_password']) {            tip("100", '<font color="red">交易密码不能与登录密码一样!</font>');        }        $status = $user->data($data)->where('id=' . $_SESSION['uid'])->save();        if ($status) {            tip("10000", '提交成功!');        } else {            tip("2", '设置失败,请重试!');        }    }
Copy after login

safeinfo-txpassadd.html 经 url 重写后实际执行的是
SafeinfoAction::txpassadd 方法
其中用到 tip 函数,不知你是如何定义的

你那 $.post 方法有 json 声明,所以 tip 函数应输出 json 格式串
而 $.post 的回调函数的参数 data 已被解析成 js 对象了
你再 var data1=eval("("+data+")"); 就有蛇足了,应去掉

你得先把你php代码调试好才行

tip 函数应写成这样

function tip($code, $msg) {    $arr['code'] = iconv('GB2312', 'UTF-8', $code);    $arr['msg'] = iconv('GB2312', 'UTF-8', $msg);         die(json_encode($arr));//    die(var_json_encode($arr));  //cjq}
Copy after login

对于 tip("100", '<font color="red">交易密码不能与登录密码一样!</font>');
得 {"code":"100","msg":"\u4ea4\u6613\u5bc6\u7801\u4e0d\u80fd\u4e0e\u767b\u5f55\u5bc6\u7801\u4e00\u6837\uff01<\/font>"}
如果写成
function tip($code, $msg) {    $arr['code'] = iconv('GB2312', 'UTF-8', $code);    $arr['msg'] = iconv('GB2312', 'UTF-8', $msg);     //    die(json_encode($arr));    die(var_json_encode($arr));  //cjq}
Copy after login

则 tip("100", '<font color="red">交易密码不能与登录密码一样!</font>');
得 {"code":"100","msg":"交易密码不能与登录密码一样!"}
就错了!

tip 函数应写成这样

function tip($code, $msg) {    $arr['code'] = iconv('GB2312', 'UTF-8', $code);    $arr['msg'] = iconv('GB2312', 'UTF-8', $msg);         die(json_encode($arr));}
Copy after login



谢谢!这样子确实有返回了,但是有个问题:
$(".tscg4").html(data.msg);  
Copy after login

中data.msg的值变成浜ゆ
怎么变回:交易密码不能与登录密码一样! 呢?
请继续指教,十分感谢!

没道理呀,这要试试

function tip($code, $msg) {  $arr['code'] = urlencode($code);  $arr['msg'] = urlencode($msg);  $s = json_encode($arr);  die(urldecode($s);}
Copy after login
Copy after login

没道理呀,这要试试

function tip($code, $msg) {  $arr['code'] = urlencode($code);  $arr['msg'] = urlencode($msg);  $s = json_encode($arr);  die(urldecode($s);}
Copy after login
Copy after login



谢谢斑竹老大,试过了,这样子ajax就无法返回了,
点击提交,只弹出了alert("ok1"); 没有弹出alert("ok2");

唉,这ajax的东东搞起来还真难搞!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles