jQuery异步提交表单的两种方式
本文为大家分享了两种jQuery异步提交表单的方式,具体内容如下
第一种方式:普通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里面的所有内容 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); }
相关推荐
delmarks 2020-06-28
89510194 2020-06-27
ppsurcao 2020-06-14
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22