HTML page:
<HTML><Head><Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8" /><Scripttype= "Text/javascript"src= "Jquery-1.8.2.min.js"></Script><Scripttype= "Text/javascript"> $(function(){ $("#send"). Click (function(){ varCont= $("input"). Serialize (); $.ajax ({URL:'ab.php', type:'Post', DataType:'JSON', Data:cont, success:function(data) {varStr=Data.username+Data.age+Data.job; $("#result"). html (str); } }); }); });</Script></Head><Body> <DivID= "Result">I'll look at the results.</Div> <formID= "my"Action=""Method= "POST"> <P><span>Name:</span><inputtype= "text"name= "username" /></P> <P><span>Age:</span><inputtype= "text"name= "Age" /></P> <P><span>Job:</span><inputtype= "text"name= "Job" /></P> </form> <ButtonID= "Send">Submit</Button></Body></HTML>
PHP Page:
<?phpheader ("Content-type:text/html;charset=utf-8"); $username = $_post[' username '); $age = $_post[' age ']; $job = $_ post[' job ']; $json _arr = Array ("username" = $username, "age" = $age, "job" = $job); $json _obj = Json_encode ($ Json_arr); Echo $json _obj;? >
One of the simplest examples of Php+jquery+ajax+json