🌐 AI搜索 & 代理 主页
Skip to content

Commit b31b9bd

Browse files
dmethvinjeresig
authored andcommitted
Add new html5 input types to list of serializable types. Older browers handle these as type="text" so they should be consistently serialized on both old and new browsers. Fixes #5667.
1 parent 6bc222e commit b31b9bd

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var jsc = now(),
22
rscript = /<script(.|\s)*?\/script>/g,
33
rselectTextarea = /select|textarea/i,
4-
rinput = /text|hidden|password|search/i,
4+
rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i,
55
jsre = /=\?(&|$)/,
66
rquery = /\?/,
77
rts = /(\?|&)_=.*?(&|$)/,

test/unit/ajax.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,18 @@ test("jQuery.ajax - dataType html", function() {
223223
test("serialize()", function() {
224224
expect(5);
225225

226+
// Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
227+
jQuery("#search").after(
228+
'<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
229+
'<input type="number" id="html5number" name="number" value="43" />'
230+
);
231+
226232
equals( jQuery('#form').serialize(),
227-
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2",
233+
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2",
228234
'Check form serialization as query string');
229235

230236
equals( jQuery('#form :input').serialize(),
231-
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2",
237+
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2",
232238
'Check input serialization as query string');
233239

234240
equals( jQuery('#testForm').serialize(),
@@ -240,14 +246,15 @@ test("serialize()", function() {
240246
'Check input serialization as query string');
241247

242248
equals( jQuery('#form, #testForm').serialize(),
243-
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
249+
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
244250
'Multiple form serialization as query string');
245251

246252
/* Temporarily disabled. Opera 10 has problems with form serialization.
247253
equals( jQuery('#form, #testForm :input').serialize(),
248-
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
254+
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
249255
'Mixed form/input serialization as query string');
250256
*/
257+
jQuery("#html5email, #html5number").remove();
251258
});
252259

253260
test("jQuery.param()", function() {

0 commit comments

Comments
 (0)