Last active
December 20, 2015 05:39
-
-
Save ipconfiger/6080185 to your computer and use it in GitHub Desktop.
ajax提交一个form表单的内容的插件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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