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.