First, a piece of code
var function (URL, func, type) { varnew Date (). GetTime (), = URL + (url.indexof ('? ') + 1 ? ' & ': '? ') + ' callback= ' + callback, = createlement ("script", {"src": url}); // Console.log (Callback, "callback") function (data) { func (data, type); }; Document.body.appendChild (s);}
This is a function of a JSONP request, where type is required for work, please ignore. It's okay to use the feeling, but I actually have a bug.
Bug generation Process
Jsonp (URL1, ajaxhandle, "xxx"); xxxx ");
When I write a call to the JSONP function, it looks like there's nothing wrong,
Two different global JSONP will be generated based on the timestamp
Jsonpcallback_date1 (),
Jsonpcallback_date2 ()
Timestamp function.
But it could actually return the same timestamp ... In other words, the second URL2 request function overrides the first request function. Causes the first URL1 not to parse correctly.
That is to say, JS almost at the same time call the two Jsonp function ...
Solution, add a random number, if the random number can also be a staggering coincidence, can only hehe.
var function (URL, func, type) { varnew Date (). GetTime () + Math.floor (math.random () * 1000000), c7/>= URL + (url.indexof ('? ') + 1?) ' & ': '? ') + ' callback= ' + callback, = createlement ("script", {"src": url}); // Console.log (Callback, "callback") function (data) { func (data, type); }; Document.body.appendChild (s);}
The outrageous JS run speed