Uncaught SyntaxError: Unexpected identifier

3.6k Views Asked by At

I'm working on a project in the Codeigniter framework. I'm getting an Uncaught SyntaxError: Unexpected identifier error in Chrome, and in Firebug I'm getting a SyntaxError: syntax error which points to the comma at the end of my second to last function. Here are the last two functions in the Prototype...

_getAeList: function(sippno) {

    $('#ae_Values').html('<div style="width:100%;"><img src="/euf/assets/images/loading.gif"/></div>');

    var listType = sippno;
    $.ajax({
        type: "POST",
        url: "/ci/ajaxCustom/AdaptEquipList",
        cache: false,
        data: "listType=" + sippno,
        datatype: "json",
        success: function(json){

            jQuery.extend(adaptequip, json);

            $("#aeSubtext").show();
            $("#ae_Values").html("<select multiple='multiple' id='adaptequip' name='adaptequip' ></select>");

            /* For compatibility with <=IE8 and other browsers that don't support Object.keys() */
            if (!Object.keys) Object.keys = function(o) {
                if (o !== Object(o))
                    throw new TypeError('Object.keys called on a non-object');
                var k=[],p;
                for (p in o) if (Object.prototype.hasOwnProperty.call(o,p)) k.push(p);
                return k;
            }

            Object.keys(adaptequip)
                .sort(function(a,b) {
                    return b.localeCompare(a)
                    })
                for(key in adaptequip) {
                    var val = adaptequip[key];

                    var sippnohand = ["MVAR","STAR"];
                    var inarray = $.inArray(sippno, sippnohand);

                    /* Check the code against array of no hand controls */
                    if(inarray > -1 && val.aeid == 1) {
                        $('#adaptequip').append('<option value="' + val.aeid + '" disabled>' + val.aename + '</option>');
                    } else {
                        $('#adaptequip').append('<option value="' + val.aeid + '">' + val.aename + '</option>');
                    }

                }

            $('#ae_Values').append('</select>');
            $("#selected_ae").show();

            $("#adaptequip").click("option", function() {
                $('#selected_ae_list').empty();
                RightNow.Widget.AdaptiveEquipment.prototype._createAeArray()
            });
        }
    });
}, <---------- Here is the comma that firebug points to

_createAeArray: function() {

    var aeArray = [];
    var textvals = [];

    $('#adaptequip :selected').each(function(i, selected){
        textvals[i] = $(this).text();
        aeArray[i] = $(this).val();
    });

        for (var i=0,l=textvals.length; i<l; i++) {
            $('#selected_ae_list').append(textvals[i] + '<br/>');
        }

        /* Check to see if AE items are selected and display a notification */
        if (textvals.length === 0) {
            $("#warning_select_ae").html('<img src="/euf/assets/images/orangeex.png" height="15"/> Please select at least one option.');
        } else {
            $("#warning_select_ae").html('<img src="/euf/assets/images/check.png" height="15"/>');
        }

        /* Apply aeArray to aeValues input form */
        $('#aeValues').val(aeArray);
        sippcode.no = sippno;
}

The comma is supposed to be there so the error I'm getting seems very vague. Any help would be appreciated.

2

There are 2 best solutions below

0
On

I actually had a comment in a previous function in the same prototype that was commented with an rather than a /* JS style comment /* which was causing the error.

It was strange that firebug was pointing to the comma after the second to last function... I'm not sure how the browser was processing the characters to cause that error.

2
On

You need to include above structure under particular Javascript object having functions as properties that can be comma seperated.

Please refer to below code

var objStructure = {
_getAeList: function(sippno) {

    $('#ae_Values').html('<div style="width:100%;"><img src="/euf/assets/images/loading.gif"/></div>');

    var listType = sippno;
    $.ajax({
        type: "POST",
        url: "/ci/ajaxCustom/AdaptEquipList",
        cache: false,
        data: "listType=" + sippno,
        datatype: "json",
        success: function(json){

            jQuery.extend(adaptequip, json);

            $("#aeSubtext").show();
            $("#ae_Values").html("<select multiple='multiple' id='adaptequip' name='adaptequip' ></select>");

            /* For compatibility with <=IE8 and other browsers that don't support Object.keys() */
            if (!Object.keys) Object.keys = function(o) {
                if (o !== Object(o))
                    throw new TypeError('Object.keys called on a non-object');
                var k=[],p;
                for (p in o) if (Object.prototype.hasOwnProperty.call(o,p)) k.push(p);
                return k;
            }

            Object.keys(adaptequip)
                .sort(function(a,b) {
                    return b.localeCompare(a)
                    })
                for(key in adaptequip) {
                    var val = adaptequip[key];

                    var sippnohand = ["MVAR","STAR"];
                    var inarray = $.inArray(sippno, sippnohand);

                    /* Check the code against array of no hand controls */
                    if(inarray > -1 && val.aeid == 1) {
                        $('#adaptequip').append('<option value="' + val.aeid + '" disabled>' + val.aename + '</option>');
                    } else {
                        $('#adaptequip').append('<option value="' + val.aeid + '">' + val.aename + '</option>');
                    }

                }

            $('#ae_Values').append('</select>');
            $("#selected_ae").show();

            $("#adaptequip").click("option", function() {
                $('#selected_ae_list').empty();
                RightNow.Widget.AdaptiveEquipment.prototype._createAeArray()
            });
        }
    });
}, // comma separation will works now
_createAeArray: function() {

    var aeArray = [];
    var textvals = [];

    $('#adaptequip :selected').each(function(i, selected){
        textvals[i] = $(this).text();
        aeArray[i] = $(this).val();
    });

        for (var i=0,l=textvals.length; i<l; i++) {
            $('#selected_ae_list').append(textvals[i] + '<br/>');
        }

        /* Check to see if AE items are selected and display a notification */
        if (textvals.length === 0) {
            $("#warning_select_ae").html('<img src="/euf/assets/images/orangeex.png" height="15"/> Please select at least one option.');
        } else {
            $("#warning_select_ae").html('<img src="/euf/assets/images/check.png" height="15"/>');
        }

        /* Apply aeArray to aeValues input form */
        $('#aeValues').val(aeArray);
        sippcode.no = sippno;
}
};