您好,欢迎访问一九零五行业门户网

thinkphp 3.1 参数处理问题

修改一个已经做好的系统,参数获取方式看不懂,请大神指教
页面提交到action处理后
结尾部分参数代码是这样写的
echo '{code:0,giftpath:' . $smallicon . ',giftstyle:' . $giftinfo['giftstyle'] . ',giftgroup:' . $giftinfo['sid'] . ',gifttype:' . $giftinfo['gifttype'] . ',touserno:' . $emceeinfo['curroomnum'] . ',isgift:0,giftlocation:[],gifticon:' . $giftinfo['gifticon'] . ',giftswf:' . $giftinfo['giftswf'] . ',touserid:' . $_request['toid'] . ',tousername:' . $emceeinfo['nickname'] . ',userno:' . $_session['roomnum'] . ',giftcount:' . $_request['count'] . ',userid:' . $_session['uid'] . ',giftname:' . $giftinfo['giftname'] . ',username:' . $_session['nickname'] . ',giftid:' . $giftinfo['id'] . '}';exit;
然后处理参数是在js里完成的
var obj_box=data[ct]; //这里不明白这个data[ct]代表什么,查找整个项目也找不到相关代码obj_box=obj_box.replace(/\+/g,%20);obj_box=evaljson(decodeuricomponent(obj_box));var gifticon=obj_box.gifticon,giftnum=obj_box.giftcount,giftname=obj_box.giftname,giftimg='',isgift=obj_box.isgift || 0,ugood=obj_box[userno],uid=obj_box[userid],uname=decodeuricomponent(obj_box[username]),cugood=this.chatgnum(obj_box[userno]),tougood=obj_box[touserno],touid=obj_box[touserid],touname=decodeuricomponent(obj_box['tousername']),tocugood=this.chatgnum(obj_box[touserno]),gifttop=parseint($('#gift_history li').size()) || 0;
上面这里也不明白,obj_box.gifticon 和obj_box[username] 是一样的么?
最后,最大的问题来了,我在action末端参数中加了一个参数,在action里测试是有数值的,但是就是传不到js里,不知道哪里出的问题
回复讨论(解决方案) zjcoin这个就是自己加的参数
echo '{code:0,zjcoin:' . $zjcoin . ',giftpath:' . $smallicon . ',giftstyle:' . $giftinfo['giftstyle'] . ',giftgroup:' . $giftinfo['sid'] . ',gifttype:' . $giftinfo['gifttype'] . ',touserno:' . $emceeinfo['curroomnum'] . ',isgift:0,giftlocation:[],gifticon:' . $giftinfo['gifticon'] . ',giftswf:' . $giftinfo['giftswf'] . ',touserid:' . $_request['toid'] . ',tousername:' . $emceeinfo['nickname'] . ',userno:' . $_session['roomnum'] . ',giftcount:' . $_request['count'] . ',userid:' . $_session['uid'] . ',giftname:' . $giftinfo['giftname'] . ',username:' . $_session['nickname'] . ',giftid:' . $giftinfo['id'] . '}';
var zjcoin = obj_box[zjcoin];//或者var zjcoin = obj_box.zjcoin;都无法获得值,提示未定义
这个php代码是ajax里后台向页面返回值的,在前台取json的值,看看js 的ajax是怎么取json的值就ok
这个php代码是ajax里后台向页面返回值的,在前台取json的值,看看js 的ajax是怎么取json的值就ok
能给一段正常json取值的代码么?我好对比一下。
在这段代码中,唯一看到跟取值有关的就是一句 var obj_box=data[ct]; 这个data从哪来的 ct又代表什么,完全没有头绪
查了一些json的资料,例如:
function showjson() { var user = { username:andy, age:20, info: { tel: 123456, cellphone: 98765}, address: [ {city:beijing,postcode:222333}, {city:newyork,postcode:555666} ] } alert(user.username); alert(user.age); alert(user.info.cellphone); alert(user.address[0].city); alert(user.address[0].postcode); user.username = tom; alert(user.username); }

上例代码中,至少还有一个var user={ ... } 来存储json的代码,但是直接{...}这样编写的话,又该如何取值?
查了一些json的资料,例如:
function showjson() { var user = { username:andy, age:20, info: { tel: 123456, cellphone: 98765}, address: [ {city:beijing,postcode:222333}, {city:newyork,postcode:555666} ] } alert(user.username); alert(user.age); alert(user.info.cellphone); alert(user.address[0].city); alert(user.address[0].postcode); user.username = tom; alert(user.username); }

上例代码中,至少还有一个var user={ ... } 来存储json的代码,但是直接{...}这样编写的话,又该如何取值?
遍历获取
user[0].username
5楼的朋友没明白我的问题,
我这样说吧
在 thinkphp3.1的框架下
tpl中的 show.html 页面中进行了一些动作的提交,
提交到了lib中的showaction.class.php的其中一个方法sendmsg()代码如下
public funciton sendmsg()
{
//处理代码....忽略...
echo '{code:0,msg:message1}'; //这一段就是返回给html信息的代码了,直接echo{参数...}
exit;
}
取值的时候,是在javascript中的
var obj_box=data[ct];
按照原来的代码,
obj_box.code 或者 obj_box[code]都能取到值,可是我自己手动新增一个参数的话,就无法取值了,查过在action中是有值的,那么就是传输中出的问题,不知道大家有没有用过这种编写方式?
你自己增加的参数是怎么写的?
你自己增加的参数是怎么写的?
原先的action中的代码是
public funciton sendmsg()
{
//处理代码....忽略...
echo '{code:0,giftpath:' . $smallicon . '......}';
exit;
}
增加参数后代码是
public funciton sendmsg()
{
//处理代码....忽略...
echo '{code:0, “zjcoin”:'.$zjcoin.',giftpath:' . $smallicon . '......}';//红色的部分是增加的参数
exit;
}
在js中,其他的参数可以用obj_box[]来获取,可我自己添加的这个参数就是取不到,数值是有的,添加到数据库都看到值了。
又有了新的发现,另外一个js文件中
var giftctrl={ sendgift:function(){ var url=/index.php/show/show_sendgift/eid/+_show.emceeid+/toid/+giftctrl.gift_to_id+/count/+giftnum+/gid/+giftctrl.gift_id+/t/+math.random(); var tmpgid=giftctrl.gift_id; giftctrl.cleargiftcfg(); $.getjson(url,function(json){ if(json){ if(json.code==0){ giftctrl.gift_to_id=_show.emceeid; $('#giftto').html(_show.emceenick); chat.getuserbalance();//用户秀币更新 dom.$swfid(flashcallchat)._chattosocket(0, 2, '{_method_:sendgift,giftpath:' + json.giftpath + ',giftstyle:' + json.giftstyle + ',giftgroup:' + json.giftgroup + ',gifttype:' + json.gifttype + ',touserno:' + json.touserno + ',isgift:' + json.isgift + ',giftlocation:' + json.giftlocation + ',gifticon:' + json.gifticon + ',giftswf:' + json.giftswf + ',touserid:' + json.touserid + ',tousername:' + json.tousername + ',userno:' + json.userno + ',giftcount:' + json.giftcount + ',userid:' + json.userid + ',giftname:' + json.giftname + ',username:' + json.username + ',giftid:' + json.giftid + ',zjcoin:' + json.zjcoin + '}');//这一段参数的顺序跟action中的顺序一样,末尾也加了zjcoin,结果还是无法获取 }}
最后那一段参数的顺序跟action中的顺序一样,我在末尾也加了zjcoin,结果还是无法获取
此楼,30分即可.
此楼,30分即可.
请指教? 终于知道原因了,原来参数传递还要通过一个swf文件, 网上下了几个能编辑swf代码的工具,能打开修改,但是一保存就弹出错误,不知道哪位大神有这样的工具,能编辑swf里面代码的工具
被保护?
其它类似信息

推荐信息