使用异步提交表单

来源:互联网 发布:域名如何使用 编辑:程序博客网 时间:2024/05/17 01:10

第一种方式

  • 普通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);        }
0 0
原创粉丝点击