1/** 2 * AJAX form plugin for jQuery 3 * 4 * @copyright Copyright (c) 2009 Jan Marek 5 * @license MIT 6 * @link http://nettephp.com/cs/extras/ajax-form 7 * @version 0.1 8 */ 9 10jQuery.fn.extend({ 11 ajaxSubmit: function (callback) { 12 var form; 13 var sendValues = {}; 14 15 // submit button 16 if (this.is(":submit")) { 17 form = this.parents("form"); 18 sendValues[this.attr("name")] = this.val() || ""; 19 20 // form 21 } else if (this.is("form")) { 22 form = this; 23 24 // invalid element, do nothing 25 } else { 26 return null; 27 } 28 29 // validation 30 if (form.get(0).onsubmit && form.get(0).onsubmit() === false) return null; 31 32 // get values 33 var values = form.serializeArray(); 34 35 for (var i = 0; i < values.length; i++) { 36 var name = values[i].name; 37 38 // multi 39 if (name in sendValues) { 40 var val = sendValues[name]; 41 42 if (!(val instanceof Array)) { 43 val = [val]; 44 } 45 46 val.push(values[i].value); 47 sendValues[name] = val; 48 } else { 49 sendValues[name] = values[i].value; 50 } 51 } 52 53 // send ajax request 54 var ajaxOptions = { 55 url: form.attr("action"), 56 data: sendValues, 57 type: form.attr("method") || "get" 58 }; 59 60 if (callback) { 61 ajaxOptions.success = callback; 62 } 63 console.log(ajaxOptions); 64 65 if($(this).data("target")) 66 { 67 $( $(this).data("target") ).html("").addClass("loading"); 68 } 69 70 return jQuery.ajax(ajaxOptions); 71 } 72});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.