I am using PHP and JavaScript. My JavaScript code contains a function, get_data():
function get_Data(){
var name;
var job;
.....
return buffer;
}
Now I have PHP code with the following.
<?php
$i=0;
$buffer_data;
/* Here I need to get the value from JavaScript get_data() of buffer;
and assign to variable $buffer_data. */
?>
How do I assign the JavaScript function data into the PHP variable?
If you don't have experience with or need Ajax, then just stuff your data into a post/get, and send the data back to your page.
JavaScript code is executed clientside while PHP is executed serverside, so you'll have to send the JavaScript values to the server. This could possibly be tucked in
$_POST
or through Ajax.You would have to use Ajax as a client-side script cannot be invoked by server-side code with the results available on server side scope. You could have to make an Ajax call on the client side which will set the PHP variable.
Use jQuery to send a JavaScript variable to your PHP file:
In your PHP code, get your variables from
$_GET['name']
and$_GET['job']
like this: