Welcome

首页 / 脚本样式 / JavaScript / 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);}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。