0

My code looks like this:

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);
        }
    });
}

On FF, Chrome and IE>8 everything works fine, problem is with IE8. instead perform the success' function in IE displays an error: enter image description here

Line 337 in jQuery is:

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 );
    }
},

so I've remove jQuery.trim( data )

and next I have this error: enter image description here

// 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;
},

What I can do, to make it works?

breq
  • 24,412
  • 26
  • 65
  • 106

2 Answers2

0

Had same problem on IE8. Probably your json is not a valid format. You need quotes around all attributes. Official json should have quotes, but nowadays new browsers don't care.

var json = {
    test: "a",  //wrong
    "test": "a" //correct
}

Used this on server side:

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;
Niels Steenbeek
  • 4,692
  • 2
  • 41
  • 50
-1

You are trying to assign the length value to a variable "length". This is a reserved word in Javascript browsers as far as I know

Change it to:

ln = obj.length, //here is line 357!

and change wherever you called "length" to "ln"

example:

 for ( ; i < ln; i++ ) {
user3036342
  • 1,023
  • 7
  • 15
  • Huh? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Reserved_Words – Yury Tarabanko Jun 26 '14 at 09:04
  • Those words (Reserved for browser) are not actually reserved. They are already defined in global scope, that's it. You are free to define a local variable with this name. Have you ever run into any issue with any of them? I have been using `length`, `parent`, and `open` for ages without any problems. – Yury Tarabanko Jun 26 '14 at 09:45
  • `ln - obj.length,` is from jQuery. – breq Jun 26 '14 at 09:46
  • when you ASSIGN A VALUE TO A VARIABLE, you cannot use the word "length" as the variable NAME!!!! var ln = obj.length; NOT var length = obj.length; just try it. it will literally take you 5 seconds to try it. if it doesn't work, then disregard my answer – user3036342 Jun 26 '14 at 09:52
  • @user3036342 In which environment? I've just tried: Chrome, FF, IE 11, node. `console.log((function(){ var length = 100; console.log(length); return length; }()))` – Yury Tarabanko Jun 26 '14 at 09:58
  • @user3036342 I have changed length to ln but it won't help also.. :( – breq Jun 26 '14 at 10:19
  • @breq It won't help. :) I've just asked a friend of mine who has a virtual machine with IE8 onboard to run the test case above. It works perfectly. – Yury Tarabanko Jun 26 '14 at 10:33
  • @YuryTarabanko, maybey the problem is with globalEval function? http://stackoverflow.com/questions/16488290/window-execscript-fails-in-ie8 I've found this topic but there is no solution... :( – breq Jun 26 '14 at 11:51
  • @breq I believe the problem is with data. Could you plz post *raw* server response (Network tab). – Yury Tarabanko Jun 26 '14 at 12:18
  • @YuryTarabanko http://i.imgur.com/paTRAhh.png according to http://jsonformatter.curiousconcept.com/ - json response is correct – breq Jun 26 '14 at 12:32
  • @breq As I can see from the picture server responded with text/html. – Yury Tarabanko Jun 26 '14 at 12:49