Submitted in Application/json and then used in PHP to read the raw data stream in the way obtained in Json_encode

Source: Internet
Author: User

The HTML is as follows:


<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> Background Management System login </TITLE>
<meta http-equiv=content-type content= "text/html; Charset=utf-8 ">
<script src= "/docs/js/jquery-1.8.1.min.js" ></script>
</HEAD>
<body>
Name: <input type= "text" name= "name" id= "name" value= "Tom"/><br/>
Age:<input type= "text" name= "Age" id= "age" value= "all"/><br/>
<textarea name= "Contents" id= "Contents" ></textarea><br/>
<a href= "#" onclick= "Javascript:tijiao ();" > Submit </a>

<div style= "height:100px;width:500px;border:1px solid red;" id= "shows" ></div>

</BODY>
</HTML>
<script>
function Tijiao ()
{
$.ajax ({
Type: "POST",
ContentType: "Application/json",
URL: '/test1.php ',//Jump to action
Data: ' {' ' name ': ' ' +$ (' #name '). Val () + ' "," Age ":" ' +$ (' #age '). Val () + ' "," Contents ":" ' +$ (' #contents '). Val () + ' "} ',
DataType: ' JSON ',
Success:function (Result) {
$ ("#shows"). HTML (result.name + "|") +result.age + "|" + result.contents);
}
});
}

</script>

Php:

<?php
$string = file_get_contents ("Php://input");
$res = Json_decode ($string, true);

echo Json_encode ($res);

?>

Submitted in Application/json and then used in PHP to read the raw data stream in the way obtained in Json_encode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.