您的位置:首页 > Web前端 > JQuery

jquery js ajax 不错的想法

2015-09-17 17:55 645 查看
<scriptlanguage="JavaScript">
$(document).ready(function(){
$('#YOUR_FORM').submit(function(){// catch the form's submit event
$.ajax({// create an AJAX call...
data: $(this).serialize(),// get the form data
type: $(this).attr('method'),// GET or POST
url: $(this).attr('action'),// the file to call
success:function(response){// on success..
$('#DIV_CONTAINING_FORM).html(response);// update the DIV}});returnfalse;});});</script>

EDIT

As pointed out in the comments sometimes the above won't work. So try the following:

<scripttype="text/javascript">var frm = $('#FORM-ID');
frm.submit(function(){
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success:function(data){
$("#SOME-DIV").html(data);},
error:function(data){
$("#MESSAGE-DIV").html("Something went wrong!");}});returnfalse;});</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: