Thinkphp3.1 parameter handling-php Tutorial

Source: Internet
Author: User
Tags sendmsg
Modify thinkphp3.1 parameter processing problems a well-established system that cannot be obtained. please kindly advise
After the page is submitted to Action for processing
The parameter code at the end is written in this way.
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;

Then the processing parameters are completed in JS.
Var obj_box = data ["ct"]; // I don't understand what this data ["ct"] represents, the code obj_box = obj_box.replace (/\ +/g, "% 20"); obj_box = evalJSON (decodeURIComponent (obj_box); var javastname, 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;

Isn't it clear that obj_box.gif tIcon and obj_box ["userName"] are the same?
Finally, the biggest problem is that I added a parameter to the parameter at the end of the ACTION. in the test of the ACTION, there is a numerical value, but it cannot be passed to the JS. I don't know what the problem is.


Reply to discussion (solution)

Zjcoin: this is the added parameter.

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"]; // or var zjcoin = obj_box.zjcoin; values cannot be obtained, prompting undefined

This php code returns the value to the page in the ajax background. take the json value at the front end to see how js ajax gets the json value.

This php code returns the value to the page in the ajax background. take the json value at the front end to see how js ajax gets the json value.


Can I provide a piece of code with a normal json value? Let me make a comparison.
In this code, the only thing that is relevant to the value is var obj_box = data ["ct"]; where does the "ct" of the data represent? there is no clue.

I checked some json data, for example:

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); } 

In the code above, there is at least one var user = {...} to store the json code, but how should we set this value if we directly write?

I checked some json data, for example:

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); } 

In the code above, there is at least one var user = {...} to store the json code, but how should we set this value if we directly write?




Retrieve through traversal
User [0]. username

My friends on the fifth floor did not understand my problem,
Let me talk about this.
Under the framework of thinkphp3.1
The show.html page in tpl submits some actions,
One of the methods submitted to showAction. class. php in lib sendMsg () is as follows:
Public funciton sendMsg ()
{
// Process the code... ignore...

Echo '{"code": "0", "msg": "message1"}'; // The code returned to the Html information, direct echo {parameter ...}
Exit;
}
When the value is set, it is in Javascript
Var obj_box = data ["ct"];
According to the original code,
The values of obj_box.code or obj_box ["code"] can be obtained. However, if I manually add a parameter, the value cannot be obtained. I have found that there is a value in the action, so there is a problem in transmission. do you know if you have used this writing method?

How do you write the added parameters?

How do you write the added parameters?


The code in the original action is
Public funciton sendMsg ()
{
// Process the code... ignore...

Echo '{"code": "0", "giftPath": "'. $ smallIcon .'"......}';
Exit;
}
After adding parameters, the code is
Public funciton sendMsg ()
{
// Process the code... ignore...

Echo '{"code": "0", "zjcoin ":"'. $ zjcoin. '"," giftPath ":"'. $ smallIcon. '"......} '; // the red part is the added parameter.
Exit;
}
In JS, other parameters can be obtained using obj_box [""], but the parameter I added myself cannot be obtained, and the value is yes. The value is displayed when it is added to the database.

Another new discovery is found in another js file.

Var GiftCtrl = {sendGift: function () {var url = "/index. php/Show/show_sendGift/eid/"+ _ show. emceeId + "/toid/" +GiftCtrl.gif t_to_id + "/count/" + giftNum + "/gid/" +GiftCtrl.gif t_id + "/t/" + Math. random (); var tmpgid1_giftctrl.gif t_id; GiftCtrl. clearGiftCfg (); $. getJSON (url, function (json) {if (json. code = 0) {GiftCtrl.gif t_to_id = _ show. emceeId; identifier ('{giftto'{.html (_ show. emceeNick); Chat. getUserBalance (); // update Dom with the user currency. $ swfId ("flashCallChat "). _ chatToSocket (0, 2, '{"_ method _": "sendGift", "giftPath": "' + json.gif tPath + '", "giftStyle ": "'+ json.gif tStyle +'", "giftGroup": "'+ json.gif tGroup +'", "giftType": "'+ json.gif tType +'", "toUserNo ": "'+ json. toUserNo + '"," isGift ":"' + json. isGift + '"," giftLocation ":"' + json.gif tLocation + '"," giftIcon ":"' + json.gif tIcon + '"," giftSwf ": "'+ json.gif tSwf +'", "toUserId": "'+ json. toUserId + '"," toUserName ":"' + json. toUserName + '"," userNo ":"' + json. userNo + '"," giftCount ":"' + json.gif tCount + '"," userId ":"' + json. userId + '"," giftName ":"' + json.gif tName + '"," userName ":"' + json. userName + '"," giftId ":"' + json.gif tId + '"," zjcoin ":"' + json. zjcoin + '"}'); // the order of this parameter is the same as that in the action. zjcoin is added at the end, and the result is still not available }}

The order of parameters in the last segment is the same as that in the action. I added zjcoin at the end, and the result still cannot be obtained.

This building is 30 minutes away.

This building is 30 minutes away.


Please advise?

Finally, I knew the cause. I had to pass the original parameter through a swf File. I had several tools on the Internet that could edit the swf code to enable the modification, but an error occurred as soon as I saved the file, I don't know which of the following tools can edit the code in swf.


Protected?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.