我的代码如下所示:
function loadData() {
$.ajax({
url: "",
async: true,
method: 'post',
dataType: "json",
data: {
start: $('input[name=start]').val(),
stop: $('input[name=end]').val(),
week: $('#weekpicker').val(),
range:$('select[name=date_control]').val(),
type: 'loaddata'
},
beforeSend: function(xhr, opts) {
if (!$('input[name=start]').val() && !$('input[name=end]').val()) {
bootbox.alert('Select date first!');
xhr.abort();
return false;
}
},
success: function(dane) {
ustawienia = dane.ustawienia;
// some code here
},
error: function(dane) {
$('button[name=pokaz]').removeAttr('disabled');
bootbox.alert(dane.responseText);
}
});
}
在FF,Chrome和IE> 8上一切正常,问题出在IE8上。 而是取得成功' IE中的函数显示错误:
jQuery中的337行是:
globalEval: function( data ) {
if ( data && jQuery.trim( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
} )( data );
}
},
所以我删除了jQuery.trim( data )
然后我有这个错误:
// args is for internal usage only
each: function( obj, callback, args ) {
var value,
i = 0,
length = obj.length, //here is line 357!
isArray = isArraylike( obj );
if ( args ) {
if ( isArray ) {
for ( ; i < length; i++ ) {
value = callback.apply( obj[ i ], args );
if ( value === false ) {
break;
}
}
} else {
for ( i in obj ) {
value = callback.apply( obj[ i ], args );
if ( value === false ) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else {
if ( isArray ) {
for ( ; i < length; i++ ) {
value = callback.call( obj[ i ], i, obj[ i ] );
if ( value === false ) {
break;
}
}
} else {
for ( i in obj ) {
value = callback.call( obj[ i ], i, obj[ i ] );
if ( value === false ) {
break;
}
}
}
}
return obj;
},
我能做些什么才能让它发挥作用?
答案 0 :(得分:0)
IE8上有同样的问题。可能你的json不是有效的格式。您需要围绕所有属性的引号。官方的json应该有引号,但现在新的浏览器都不在乎。
var json = {
test: "a", //wrong
"test": "a" //correct
}
在服务器端使用它:
JavascriptObject translationsObject = new JavascriptObject();
Dictionary<string, string> translations = Translator.GetTranslations(key.LanguageCode);
foreach (var pair in translations)
{
if (pair.Value != pair.Key)
translationsObject.Add("\"" + pair.Key + "\"", pair.Value); //Needed for <=IE8
}
string translationsString = "var translations = ";
translationsString += translationsObject.ToString();
translationsString += ";";
return translationsString;
答案 1 :(得分:-1)
您正在尝试将长度值分配给变量&#34; length&#34;。据我所知,这是 Javascript 浏览器中的保留字
将其更改为:
ln = obj.length, //here is line 357!
并在任何地方改变&#34;长度&#34;到&#34; ln&#34;
示例:
for ( ; i < ln; i++ ) {