get data from javascript to php

Solutions on MaxInterview for get data from javascript to php by the best coders in the world

showing results for - "get data from javascript to php"
Amina
15 Oct 2019
1Passing data from PHP is easy, you can generate JavaScript with it. The other way is a bit harder - you have to invoke the PHP script by a Javascript request.
2
3An example (using traditional event registration model for simplicity):
4
5<!-- headers etc. omitted -->
6<script>
7function callPHP(params) {
8    var httpc = new XMLHttpRequest(); // simplified for clarity
9    var url = "get_data.php";
10    httpc.open("POST", url, true); // sending as POST
11
12    httpc.onreadystatechange = function() { //Call a function when the state changes.
13        if(httpc.readyState == 4 && httpc.status == 200) { // complete and no errors
14            alert(httpc.responseText); // some processing here, or whatever you want to do with the response
15        }
16    };
17    httpc.send(params);
18}
19</script>
20<a href="#" onclick="callPHP('lorem=ipsum&foo=bar')">call PHP script</a>
21<!-- rest of document omitted -->
22Whatever get_data.php produces, that will appear in httpc.responseText. Error handling, event registration and cross-browser XMLHttpRequest compatibility are left as simple exercises to the reader ;)
23
24See also Mozilla's documentation for further examples
queries leading to this page
get javascript value from phpget data from javascript to phpjs get from phphow to get value from javascript to phphow to return data to javascript from phpphp data in jsjavascript use php dataget value from javascript to phprequest php data from jshow to get php javascripthow to return data from php to javascriptget javascript value in phphow to get value from js to phpjavascript receive php dataphp get value from javascript into phpget php value from jshow to get value from php to javascriptget result from php in javascripthow to get php data in javascriptget php data in javascriptjs value to phpjavascript to php dataget data from php to javascriptreturn js to phpjs return data to phphow to get javascript value in phphow to transfer the data from php to javascripthow to get php values to a java scriptgetting values from javascript in phpget data from php in jsphp data in javascripthow to get js data and use in phpjavascript get from phpuse javascript to get php dataaccess data from javascript in phpget php data to javascriptphp value from javascriptuse javascript to get value in phphow to get javascript data in phphow to get data from javascript to phppass data from javascpt to phphow to extract data from php file to javascripttransfer data from php to javascriptget data to javascript phpphp get data from javascriptaccess javascript data in phpjs get data from phphow to get data from php to javascript 24 get data from php in jssend data to javascript file from phpread php data in jsuse js data in phpget value from javascript to php code examplejavascript get data from phphow to get php data in jsjs get php datahow to get value in js from phpuse php data in javascriptget php value in jsreturn data to js phpjavascript data to phphow to use php data in javascriptget php value in javascriptjs data to php with sonhow to get data from php in javascriptget value from js to phphow to get data from js to phpget value javascript to phpdata javascript to phpphp getting value from javascriptget data from javascript to php