Php methods in Json

explain post  method in PHP Json ?

Last updated:7/3/2018 5:07:05 AM

1 Answers

Prakash nidhi Verma
Prakash nidhi Verma

JSON PHP:

Read data from a web server, and display the data in a web page is a common use of JSON. 

<?php 
$myObj->name = 'Prakash';
$myObj->age = 19;
$myObj->city = 'Allahabad';
$myJSON = json_encode($myObj);
echo $myJSON;
?>

PHP Method = POST :

When you sending data to the server,it is often best to use the HTTP POST method. 

The data sent to the server must now be an argument to the .send() method:

Example: 

obj = { 'table':'customers', 'limit':10 }; 
dbParam = JSON.stringify(obj);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        myObj = JSON.parse(this.responseText);
        for (x in myObj) {
            txt += myObj[x].name + '<br>';
        }
        document.getElementById('Mindstick').innerHTML = txt;
    }
};
xmlhttp.open('POST', 'json_demo_db_post.php', true);
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send('x=' + dbParam);

Answer