var _jsonp function var document documentElement return function var f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var _jsonp = function(a) {
var b = 0, c = a.document, e = c.documentElement;
return function(g, h) {
var d = 'frame_' + b++, f = c.createElement("script");
a[d] = function() {
try {
delete a[d];
} catch (b) {
a[d] = null;
}
e.removeChild(f);
h.apply(this, arguments);
};
e.insertBefore(f, e.lastChild).src = g + "&callback=invoke=" + d;
};
}(window);
JSONP = {
_jsonp: _jsonp,
query: function(a, b) {
this._jsonp(a.url + "?" + JSONP.dataEncode(a.data), b);
},
dataEncode: function(a) {
var b = "";
if (a) {
for (var c in a) {
a.hasOwnProperty(c) && (b += "&" + c.toString() + "=" + encodeURIComponent(a[c]));
}
if ("&" == b.charAt(0)) {
return b.substring(1, b.length);
}
}
return b;
}
};
/*
//EXAMPLE:
var obj = {
url: "http://predictor.yandex.net/suggest.json/complete",
data: {
lang: "ru",
q: "тексто",
limit: 3
}
};
JSONP.query(obj, function(res) {
console.log(res);
});
*/