我使用ajax提交创建新记录的表单而不刷新当前页面,如下所示:https://stackoverflow.com/a/6723501/1162836
这是答案中的ajax:
$('form').submit(function() {
var valuesToSubmit = $(this).serialize();
$.ajax({
type: 'POST',
url: $(this).attr('action'), //sumbits it to the given url of the form
data: valuesToSubmit,
dataType: "JSON" // you want a difference between normal and ajax-calls, and json is standard
}).success(function(json){
//act on result.
});
return false; // prevents normal behaviour
});
如何获取新创建的记录的ID?