PHP Simple JSON interaction example with HTML

Source: Internet
Author: User

Front-end (HTML) code

<html><head><title>Simple example of foreground processing JSON 
     title
 ><metacharset="Utf-8"/><scripttype="text/javascript"src=" Jquery-1.11.3.min.js "> 
     Script
 ><scripttype="Text/javascript">$ ("document"). Ready (function(){var url = "server2.php";            var data = {"do":"First"}; $.getjson (url,data,function(res){ $ ("#username"). Val (Res.userna                ME);            $ ("#password"). Val (Res.password);            });            var data = {"do":"second"}; $.getjson (url,data,function(res){ $ ("#members"). Val (res[2<            /c22>].username);        });    });  
     Script
 > 
     Head
 ><body><h2>Get User name and password 
     H2
 >User name:<inputtype="text"name= "username"id="username" /><br/>Password:<inputtype="password"name="password"ID ="password"/><br/><h2>Get member Information 
     H2
 ><textareaid="Members"> 
     textarea
 > 
     Body
 > 
     HTML
 >

Background (PHP) code


    //1. One-dimensional$member[' username '] ="Mike.";$member[' Password '] ="123";//2. Two d$members[' 1 '][' username '] ="Mike_1";$members[' 1 '][' Password '] ="123";$members[' 2 '][' username '] ="Mike_2";$members[' 2 '][' Password '] ="123123";$members[' 2 '][' Address '] ="Zhuhai";//According to the request parameters sent by the foreground to decide what action to take .$do=$_request[' Do '];Switch($do) { Case' first ':EchoJson_encode ($member); Break; Case' second ':EchoJson_encode ($members); Break; }?>

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP and HTML simple JSON interaction examples, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.