Exchanging the data from server, PHP as server language used. The JSON.parse() function is used to get the data from php or from the any other server. For the receiving the data from the server few AJAX statements to check whether the server is ready to respond the data from the server or not. If those conditions are fulfilled then the data from the php file can be received. The protocols used to sending and receiving the data from server is given by:
In the Script JSON.parse(this.responseText) function is used to parse the data into variable so that it can call the values from that object. The this.response is used to take the data from the php that is being print as a string. In the given code the php object data is being taken extracted by script of the JSON. By the AJAX function in the script are checking the data whether it is responding are not when the it has responded the data will be sent and print in the web page. The xmlhttp.open(“GET”, “geeks.php”, true) function is used to get the value from the php file geeks.php. The xmlhttp.send() function is used to send the values in to the XMLHttpRequest().
Now, extracting the data from other php script.
In the following that is sent to client and printed the result in JSON structure since it is not filtered values into each different values.
PHP Method = POST: It quiet simple if above topics had understood completely. In the following syntax changes will occur. In the POST method the arguments have to be passed via send method but in the GET method the arguments can passed when the request of the php file sent.
open("GET", file_name?x=argument, asyn, username, password)
open("POST", file_name, asyn, username, password)
The arguments are passed by the send(argument) method and send a request from the php to access data from server. So use function to get request are given below:
In the php file a header has to be added:
header("Content-Type: application/json; charset=UTF-8")
The php file given below can be saved using post.php
After doing all this in php and the html file this will be appear as follows: