本文實(shí)例講述了JQuery異步提交表單與文件上傳功能。分享給大家供大家參考,具體如下:
Jquery.form.js是一個(gè)可以異步提交表單及上傳文件的插件。
示例如下:
index.html
<!DOCTYPE html><html><head> <title></title> <meta charset="utf-8"> <script type="text/javascript" language="javascript" src="js/jquery-1.10.2.js"></script> <script type="text/javascript" language="javascript" src="js/jquery.form.js"></script> <script type="text/javascript" language="javascript"> $(function(){ //異步提交表單 $("#ajaxSubmit").on("click",function(){ console.log($(this)); $("#formToUpdate").ajaxSubmit({ type:'post', url:'p.php', success:function(data){ console.log(data); }, error:function(XmlHttpRequest,textStatus,errorThrown){ console.log(XmlHttpRequest); console.log(textStatus); console.log(errorThrown); } }); }); }); </script></head><body><form id="formToUpdate" method="post" action="#" enctype="multipart/form-data"> <input type="text" name="t1"><br /> <input type="file" name="f1"><br /> <input id="ajaxSubmit" type="button" value="異步提交"></form></body></html>
p.php
<?php/** * Created by JetBrains PhpStorm. * User: smeoi * To change this template use File | Settings | File Templates. */echo '<pre>';print_r($_POST);echo '</pre>';echo '<pre>';print_r($_FILES);echo '</pre>';
效果圖:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery form操作技巧匯總》、《jQuery文件與目錄操作技巧匯總》、《jquery中Ajax用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注