Guest User

Untitled

a guest
Mar 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. /***
  2. The serializeHash method can be used to submit forms with an ajax request.
  3. The result of serializeHash can be used as the 'data' option for jQuery's
  4. built-in ajax methods and functions.
  5. ***/
  6. (function($){
  7. $.fn.serializeHash = function() {
  8. var hash = {};
  9. /***
  10. Use serializeArray() to get an array of JSON objects for
  11. each value in the form.
  12. (As opposed to serialize() which requires string splitting)
  13. ***/
  14. $.each(this.serializeArray(), function() {
  15. if(hash[this.name] === undefined) {
  16. hash[this.name] = this.value;
  17. }
  18. else {
  19. /***
  20. Handle form elements with multiple values such as
  21. <select multiple="multiple"> and multiple
  22. <input type="checkbox"/> elements with the same name.
  23. ***/
  24. if ($.isArray(hash[this.name])) {
  25. hash[this.name].push(this.value);
  26. }
  27. else {
  28. hash[this.name] = [hash[this.name], this.value];
  29. }
  30. }
  31. });
  32. return hash;
  33. };
  34. })(jQuery);
Add Comment
Please, Sign In to add comment