2013-01-17 29 views

回答

0

参考这个网址的详细信息http://api.jquery.com/jQuery.ajax/

<form id="myform"> 
    <input type="text" name="foo" /> 
    <input type="button" value="Submit" id="submit" /> 
</form> 

$("#submit").click(function(){ 
    $.ajax({ 
     url: "/yourposturl", 
     type: "post", 
     data: $("#myform").serialize(), 
     success: function(data){ 
     //write code here manage "data" 
    }, 
    error:function(){ 
     alert("failure"); 
     $("#result").html('there is error while submit'); 
    } 
}); 

});

0

最简单的事情就是使用jQuery ajax方法或其中一种简写方法。如果你有这样的形式:

<form id="myform"> 
    <input type="text" name="foo" /> 
    <input type="button" value="Submit" id="submit" /> 
</form> 

你可以这样提交:

$("#submit").click(function(){ 
    $.post("/mycontroller/myaction", $("#myform").serialize(), function(data){ 
     //do something with the response from the controller via the data object 
    }); 
}); 

http://api.jquery.com/category/ajax/shorthand-methods/

相关问题