Php methods in Json

Total Post:113

Points:791
JSON 
 228  View(s)
Ratings:
Rate this:

explain post  method in PHP Json ?

  1. Post:140

    Points:984
    Re: Php methods in Json

    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