Skip to content

Commit c358816

Browse files
committed
Use JSON.parse directly if available.
Closes blueimp#3474
1 parent 2dfc692 commit c358816

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

js/jquery.iframe-transport.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* http://www.opensource.org/licenses/MIT
1010
*/
1111

12-
/* global define, require, window, document */
12+
/* global define, require, window, document, JSON */
1313

1414
;(function (factory) {
1515
'use strict';
@@ -27,7 +27,14 @@
2727
'use strict';
2828

2929
// Helper variable to create unique names for the transport iframes:
30-
var counter = 0;
30+
var counter = 0,
31+
jsonAPI = $,
32+
jsonParse = 'parseJSON';
33+
34+
if ('JSON' in window && 'parse' in JSON) {
35+
jsonAPI = JSON;
36+
jsonParse = 'parse';
37+
}
3138

3239
// The iframe transport accepts four additional options:
3340
// options.fileInput: a jQuery collection of file input fields
@@ -197,7 +204,7 @@
197204
return iframe && $(iframe[0].body).text();
198205
},
199206
'iframe json': function (iframe) {
200-
return iframe && $.parseJSON($(iframe[0].body).text());
207+
return iframe && jsonAPI[jsonParse]($(iframe[0].body).text());
201208
},
202209
'iframe html': function (iframe) {
203210
return iframe && $(iframe[0].body).html();

0 commit comments

Comments
 (0)