我的ajax代码
$.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) { alert("ok"); ...
tip("100", '<font color="red">交易密码不能与登录密码一样!</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}function var_json_encode($var){ $_var = var_urlencode($var); $_str = json_encode($_var); return urldecode($_str); }
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}
这样也不行:(
function tip($code, $msg) { $arr['code'] = $code; $arr['msg'] = $msg; die(json_encode($arr,JSON_UNESCAPED_UNICODE)); //cjq}
$_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; }
输出 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>...
<!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>
我要你看的是:
模板中的 $.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) {
在浏览器源码中是什么?
我要你看的是:
模板中的 $.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) {
在浏览器源码中是什么?
百思不得其解,困惑啊!
师者,所以传道、授业、解惑也,谁是我的老师呢?
你为什么要省略在浏览器中看到的代码呢?
$.post('{:U("Safeinfo/txpassadd")}', $("#txadd").serialize(), function(data) { alert("ok"); ...},"json");
你为什么要省略在浏览器中看到的代码呢?
<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 src="/Public/frontend/images/ico/home.png" style="max-width:90%" style="max-width:90%" class="png_fix" title="我的巨轮贷"/ alt="die(json_encode(. 没返回" ><a href="/usercontent-index.html">我的巨轮贷</a></div> <ul class="left_navi"> <li class="zj "><img src="/Public/frontend/images/ico/005.png" style="max-width:90%" style="max-width:90%" class="png_fix" title="资金管理"/ alt="die(json_encode(. 没返回" ><img src="/Public/frontend/images/ico/005_2.png" style="max-width:90%" style="max-width:90%" class="img1" 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 src="/Public/frontend/images/ico/062.png" style="max-width:90%" style="max-width:90%" class="png_fix" title="投资管理"/ alt="die(json_encode(. 没返回" ><img src="/Public/frontend/images/ico/062_1.png" style="max-width:90%" style="max-width:90%" class="img1" 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 src="/Public/frontend/images/ico/009.png" style="max-width:90%" style="max-width:90%" class="png_fix" title="借贷管理"/ alt="die(json_encode(. 没返回" ><img src="/Public/frontend/images/ico/009_2.png" style="max-width:90%" style="max-width:90%" class="img1" 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 src="/Public/frontend/images/ico/011.png" style="max-width:90%" style="max-width:90%" class="png_fix" title="账户管理"/ alt="die(json_encode(. 没返回" ><img src="/Public/frontend/images/ico/011_1.png" style="max-width:90%" style="max-width:90%" class="img1" 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 src="/Public/frontend/images/ico/022.png" style="max-width:90%" style="max-width:90%" class="png_fix" title="互动管理"/ alt="die(json_encode(. 没返回" ><img src="/Public/frontend/images/ico/022_1.png" style="max-width:90%" style="max-width:90%" class="img1" 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>安全信息</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>
你这个对吗?
既没有看到 id=txadd 的标记,已没有看到 $.post(.... 代码
你这个对吗?
既没有看到 id=txadd 的标记,已没有看到 $.post(.... 代码
<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>
既然是在框架里,那你就贴出框架里看到的 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>
敬爱的@xuzuning 老师,您好,怎么没下文啦?
点击提交,只弹出了alert("ok1"); 没有弹出alert("ok2"); 这到底是为什么呢?
safeinfo-txpassadd.html 代码?
safeinfo-txpassadd.html 代码?
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", '设置失败,请重试!'); } }
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}
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}
tip 函数应写成这样
function tip($code, $msg) { $arr['code'] = iconv('GB2312', 'UTF-8', $code); $arr['msg'] = iconv('GB2312', 'UTF-8', $msg); die(json_encode($arr));}
$(".tscg4").html(data.msg);
没道理呀,这要试试
function tip($code, $msg) { $arr['code'] = urlencode($code); $arr['msg'] = urlencode($msg); $s = json_encode($arr); die(urldecode($s);}
没道理呀,这要试试
function tip($code, $msg) { $arr['code'] = urlencode($code); $arr['msg'] = urlencode($msg); $s = json_encode($arr); die(urldecode($s);}
唉,这ajax的东东搞起来还真难搞!