本文為大家分享了兩種jQuery異步提交表單的方式,具體內(nèi)容如下
第一種方式:普通ajax方式提交
$(function(){ $('#send').click(function(){ $.ajax({ type: "GET", url: GLOBAL_PATH + "/Enterprise/savecompanyphoto", data: {username:$("#username").val(), content:$("#content").val()}, dataType: "json", success: function(data){ $('#resText').empty(); //清空resText里面的所有內(nèi)容 var html = ''; $.each(data, function(commentIndex, comment){ html += '<div class="comment"><h6>' + comment['username'] + ':</h6><p class="para"' + comment['content'] + '</p></div>'; }); $('#resText').html(html); } }); });});
第二種方式:普通ajaxSubmit方式提交表單
<script src="jquery.form.js" type="text/javascript"></script><script src="dialog.js?lib=false" type="text/javascript"></script>src="jquery.min.js" type="text/javascript">function uploader_img(){ var optionsSave={ type: "POST", url: GLOBAL_PATH + "/Enterprise/savecompanyphoto", data:$('#addImg').serialize(), success: function (data) { if (data.code == 0) { AlertMini('alt1', "上傳圖片成功!", 'success.gif', 2); window.location.reload(); } else { AlertMini('alt1', "上傳圖片失敗!", 'error.gif', 2); } }, error: function (data) { AlertMini('alt1', "上傳圖片失敗!", 'error.gif', 2); } } $('#addImg').ajaxSubmit(optionsSave); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注