How can php get JS values? I am a newbie who has been tossing for a few days. please give me some advice.

Source: Internet
Author: User
How to obtain JS values in php. I am a newbie for a few days. please give me some advice! How can I modify the following code to get the & nbsp; $ key & nbsp; value & nbsp; & lt; script & nbsp; type = "text/javascript" & gt; TOP. api ('rest', & nbsp; 'php how to obtain JS values, please enlighten me after a few days of hard work!
How can I modify the following code to obtain the $ key value?



TOP. api ('rest', 'get ',{
// Method: 'Taobao. taobake. items. convert ',
Method: 'Taobao. taobake. widget. items. convert ',
Num_iids :' ',
Fields: 'Num _ iid, click_url, commission_rate'
}, Function (resp ){
If (resp. error_response ){
Alert ('Taobao. taobake. widget. items. convert interface failed to get commodity information! '+ Resp. error_response.msg );
Return false;
}
 
Var respItem = resp. taobaoke_items.taobaoke_item;
For (var I = 0; I <respItem. length; I ++ ){
Abc = respItem [I]. num_iid;
}
})
Script
$ Key = "script document. write (abc); script";
Echo $ key; // could you tell me how the heroes can modify it to get the value!
?>



------ Solution --------------------
No. PHP is the server-side language and JS is the browser-side language. Apache first executes the PHP code, parses it into HTML code, downloads it to the user's browser, and then executes the JS language for further rendering. So when your code runs PHP first, and then TOP. api, it is disconnected from apache when it is executed to script document. write (abc) and script.
------ Solution --------------------
The upstairs is correct. use AJAX !!!
------ Solution --------------------


TOP. api ('rest', 'get ',{
// Method: 'Taobao. taobake. items. convert ',
Method: 'Taobao. taobake. widget. items. convert ',
Num_iids :' ',
Fields: 'Num _ iid, click_url, commission_rate'
}, Function (resp ){
If (resp. error_response ){
Alert ('Taobao. taobake. widget. items. convert interface failed to get commodity information! '+ Resp. error_response.msg );
Return false;
}

Var respItem = resp. taobaoke_items.taobaoke_item;
For (var I = 0; I <respItem. length; I ++ ){
Abc = respItem [I]. num_iid;
}
$. Post ('', {abc: abc}, function (data) {}) // add an ajax request here
})
Script
If (isset ($ _ POST ['ABC'])
{
$ Abc = $ _ POST ['ABC'];
Echo $ abc;
}
?>

You can use ajax to modify your code.
------ Solution --------------------
In fact, data obtained from the client through js can be submitted through an event-driven approach. one is ajax, and the other is to trigger the submission when certain conditions are met, for example, through setTimeout, if certain conditions are met, submit is triggered. In short, it can meet the needs of lz.

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.