FormData objects submit the form and submit the form form

Link: https: //www.cnblogs.com/chwlhmt/p/8439135.html

(Invasion deleted)

 

formdat to

This is new in HTML5 API 

Advantages: FormData can read not only the form data, the data itself can be added

html:

<form name="form1" id="form1">  
        <p>name:<input type="text" name="name" /></p>  
        <p>gender:<input type="radio" name="gender" value="1" />male <input type="radio" name="gender" value="2" />female</p>
        <p>stu-number:<input type="text" name="number" /></p>  
        <p>photo:<input type="file" name="photo" id="photo"></p>  
        <p><input type="button" name="b1" value="submit" onclick="fsubmit()" /></p>  
</form>

 

js:

fsubmit function () {
         var form = document.getElementById ( "Form1" ); 
        var FD = new new the FormData (form); 
        $ .ajax ({ 
             URL: "server.php" , 
             type: "the POST" ,
              Data: FD, 
             the processData : to false ,   // tell jQuery not to process data transmitted 
             contentType: to false ,    // tell jQuery not to set the request Content-Type header 
             Success: function (Response, Status, XHR) { 
                the console.log (XHR); 
                var JSON = $ .parseJSON (response); 
             }
        });
        return false;
}

 

Value judgment

html:

<form id="formid" name="myform" method='post' onsubmit="return checkUser();" >
    <input type="text" value="" class="text2" name="username" id="userid"/></td>
<input type="password" value="" class="text2" name="userpass" id="userpassid"/></td> <input type="submit" value="" class="btn2" /> </form>

js:

function checkUser () { 
  var Result = document.getElementById ( "the userid" ) .Value; 
  var password = document.getElementById ( "passid" ) .Value; 

  IF (! Result) { 
    Alert ( "user name can not be empty" );
    return  to false ; 
  } 
  IF (! password) { 
    Alert ( "empty entry is not" );
    return  to false ; 
  } 
  document.getElementById ( "FormID" ) .submit (); 
}

 

Guess you like

Origin www.cnblogs.com/cmz-32000/p/11683409.html