I've got this Knockout custom binding, all alone in one file (allowing to bind to a jQuery widget):
(function ($, ko, undefined) {
ko.bindingHandlers.switch = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
$(element).switch(valueAccessor());
}
};
}(jQuery, ko));
The project This file is downloaded at some point using the jQuery._evalUrl
function. I could describe the whole process, but I'm not sure it would be relevant.
The problem is that in IE8, I get the good old error 80020101 during the $.ajax from the function.
I looked around and found that this error can happen for almost any reason ( see these questions that sum up some of them).
I didn't find any JS error in the file (but I'm not a JS guru), and eventually looked at the jQuery._evalUrl
function. Here is the source in jQuery 1.11.1:
jQuery._evalUrl = function( url ) {
return jQuery.ajax({
url: url,
type: "GET",
dataType: "script",
async: false,
global: false,
"throws": true
});
};
Out of despair, I changed
dataType: "script",
to
dataType: "text/javascript",
and... that worked.
But in fact, writing
dataType: "dummy",
worked as well. But removing the entire dataType
line didn't.
I'm not sure I get why. Is the code evaluated when dataType="script"
and not otherwise ?
So I tried to rewrite the custom binding step by step, testing all the way down, to track a potential code problem using the original dataType: "script"
.
This doesn't raise an error:
(function ($, ko, undefined) {
}(jQuery, ko));
This does:
(function ($, ko, undefined) {
ko.bindingHandlers.switch = {
};
}(jQuery, ko));
In fact, those two also fail:
(function ($, ko, undefined) {
ko.bindingHandlers.switch = 1;
}(jQuery, ko));
(function ($, ko, undefined) {
ko.bindingHandlers.switch = "a";
}(jQuery, ko));
Any ideas what the hell could be happening ?