AJAX-----The new API---FormData in 13HTML5

Source: Internet
Author: User

FormData form data Object, which is a new API in HTML5, he can use form objects to do parameters, automatically package the form's data, when Ajax is sending data, send the form data within the FormData to the backend

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Script>    functionfd () {varFDate=document.getElementById ('FDate'); varFD= NewFormData (fdate); varXHR= NewXMLHttpRequest (); Xhr.open ('Post','10.php',true);        Xhr.send (FD); Xhr.onreadystatechange= function(){            if( This. ReadyState== 4) {document.getElementById ('desc'). InnerHTML=  This. responsetext; }        }            }</Script><Body>    <formID= "FDate" >User:<inputtype= "text"name= "User"> <BR><BR>Age :<inputtype= "text"name= "Age"> <BR><BR>Sex:<inputtype= "text"name= "Sex"> <BR><BR>QQ:<inputtype= "text"name= "QQ"> <BR><BR>        <inputtype= "button"value= "Go"onclick= "FD ();">     </form>    <PID= "desc"></P></Body></HTML>

The effect is as follows:

This is much simpler than the traditional stitching method, and of course he has another usage as follows:

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Script>    functionfd () {varFDate=document.getElementById ('FDate'); varFD= NewFormData (fdate); varFD2= NewFormData (); varXHR= NewXMLHttpRequest (); Xhr.open ('Post','10.php',true); //Xhr.send (FD);Fd2.append ('User','Leigood'); Fd2.append (' Age',' -');        Xhr.send (FD2); Xhr.onreadystatechange= function(){            if( This. ReadyState== 4) {document.getElementById ('desc'). InnerHTML=  This. responsetext; }        }            }</Script><Body>    <formID= "FDate" >User:<inputtype= "text"name= "User"> <BR><BR>Age :<inputtype= "text"name= "Age"> <BR><BR>Sex:<inputtype= "text"name= "Sex"> <BR><BR>QQ:<inputtype= "text"name= "QQ"> <BR><BR>        <inputtype= "button"value= "Go"onclick= "FD ();">     </form>    <PID= "desc"></P></Body></HTML>

The effect is as follows:

AJAX-----The new API---FormData in 13HTML5

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.