Ajax Submission Form Minimalist posture

Source: Internet
Author: User

<script type= "Text/javascript" >    function submitform ()  {         var action_url = $ (' form[name= ' Form-oem-add "]). attr ( ' Action ');         var action_type = $ (' form[name= ') Form-oem-add "]). attr (' method ');         //var post_data =  $ (' form[name= ' Form-oem-add "]). Serialize ();         var post _data = new formdata ($ (' form[name= ' Form-oem-add "] ') [0]);         $.ajax ({            type: action_ Type.touppercase (),             url: action_ url,            data: post_data,//  Forms to submit &NBSP;&NBSP;&NBSP;&NBSP;&NBsp;       async: false,             cache: false,             contentType: false,             processdata: false,            success:  function  (msg)  {                 if  (msg.errorcode == 1)  {         &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;POPX (msg.errorMsg, 5);                 } else {                    &NBSP;&NBSP;POPX (' New success ',  5);                }             }        } );    }</script>



It is important to note that:

    1. The three attributes in the form are integral
      <form name= "" action= "" method= "" >


When a file field does not exist in the form, you can use the serialization of jquery to package the data directly

var post_data = $ (' form[name= "Form-oem-add"] '). Serialize ()


When a file field exists in the form, you can use the HTML5 form data object to package the data

var post_data = new FormData ($ (' Form[name= "Form-oem-add"] ') [0])




This article is from the "My PHP Road" blog, reproduced please contact the author!

Ajax Submission Form Minimalist posture

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.