Skip to content

Instantly share code, notes, and snippets.

@ipconfiger
Last active December 20, 2015 05:39
Show Gist options
  • Save ipconfiger/6080185 to your computer and use it in GitHub Desktop.
Save ipconfiger/6080185 to your computer and use it in GitHub Desktop.
ajax提交一个form表单的内容的插件
(function($) {
// ajax提交一个form表单的内容的插件
$.fn.extend(
{
Submit:function(callback){
$(this).each(function(i){
var form = $(this);
var params = {};
var url = form.attr("action");
console.log(url);
form.find(".submit").each(function(idx){
console.log("click");
$(this).click(function(){
form.find("input").each(function(idx){
var input = $(this);
params[input.attr("name")]=input.val();
});
form.find("select").each(function(idx){
var input = $(this);
params[input.attr("name")]=input.val();
});
console.log(params);
$.post(url,params,function(data, status){
callback(data, status);
},'json');
});
});
});
}
}
);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment