<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:
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