admin管理员组

文章数量:1326118

so I have this unexpected end of input in my JS, it is in line 1 and I really can't understand what is it, here's the code:

window.HandlePageCommand = function (mandName) {

    document.getElementById("buffer").innerHTML = mandName + " | " + window.ActiveForm.Name;
    var activeForm = window.ActiveForm;
    var call;
    var callback;
    var requestData;
    var grid;

    if (mandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (mandName === "ADD_PERIOD") {

        target = activeForm.Sections[1];
        window.SelectedState = {};
        activeForm.BindUI(window.SelectedState);
        grid = window.RegisteredControls.Grids["Semestres"];

        grid.AddedEntities = [];
        grid.DeletedEntities = [];
        grid.Databind([]);
        Exertus.MainModalPanel.Show("Detalle", target);
        return;
    }

    if (mandName === "ADD_MATERIAL") {

        target = activeForm.Sections[1];
        window.SelectedState = {};
        activeForm.BindUI(window.SelectedState);
        grid = window.RegisteredControls.Grids["GRID_DE_MATERIALES"];

        grid.AddedEntities = [];
        grid.DeletedEntities = [];
        grid.Databind([]);
        Exertus.MainModalPanel.Show("DETAIL", target);
        return;
    }


    if (activeForm.Name === "Periodos") {

        callback = function (responseData) {
            var innerGrid = window.RegisteredControls.Grids["Semestres"];
            var responseInfo = jQuery.parseJSON(responseData);
            innerGrid.Databind(responseInfo.Users);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }

        if (window.ActiveForm.Validate() != true) {
            return;
        }

        window.SetLoading(true);
        call = new Exertus.ServerCall("MainWebModule");
        this.SelectedPeriod = this.SelectedPeriod || {};
        activeForm.BindEntity(this.SelectedPeriod);
        grid = window.RegisteredControls.Grids["Semestres"];

        requestData = {
            PeriodData: this.SelectedPeriod
        }
        call.Execute("SavePeriodChanges", requestData, callback);
        return;

    }

    if (mandName === "GUARDAR") {

        if (activeForm.Name === "Factores de Venta 1") {
            var callback = function (responseData) {
                window.OriginalFactors = jQuery.extend({}, window.FactorsInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.FactorsInfo = window.FactorsInfo || {};
            activeForm.BindEntity(window.FactorsInfo);
            call.Execute("SaveFactors", window.FactorsInfo, callback);
            return;
        }


            if (mandName === "SAVE") {

        if (activeForm.Name === "Direcciones") {
            var callback = function (responseData) {
                window.OriginalAddress = jQuery.extend({}, window.AddressInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.AddressInfo = window.AddressInfo || {};
            activeForm.BindEntity(window.AddressInfo);
            call.Execute("SaveAddress", window.AddressInfo, callback);
            return;
        }

            if (mandName === "SAVE") {

        if (activeForm.Name === "Materiales") {
            var callback = function (responseData) {
                window.OriginalMaterials = jQuery.extend({}, window.MaterialsInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.MaterialsInfo = window.MaterialsInfo || {};
            activeForm.BindEntity(window.MaterialsInfo);
            call.Execute("SaveMaterials", window.MaterialsInfo, callback);
            return;
        }

    if (mandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (mandName === "GUARDAR") {

        if (activeForm.Name === "Factores de Venta 2") {
            var callback = function (responseData) {
                window.OriginalFactorsBoundaries = jQuery.extend({}, window.FactorsBoundariesInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.FactorsBoundariesInfo = window.FactorsBoundariesInfo || {};
            activeForm.BindEntity(window.FactorsBoundariesInfo);
            call.Execute("SaveFactors", window.FactorsBoundariesInfo, callback);
            return;
        }

    if (mandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (mandName === "SAVE_CHANGES") {
        var callback = function (responseData) {
            var innerGrid = arguments.callee.Grid;
            var entities = jQuery.parseJSON(responseData);
            window.FamilyProductsTypes = entities;

            innerGrid.AddedEntities = [];
            innerGrid.ModifiedEntities = {};
            innerGrid.DeletedEntities = [];

            innerGrid.Databind(entities);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }


        var grid = window.RegisteredControls.Grids["Artículos"];

        if (grid.HasChanges() != true) {
            Exertus.MainModalPanel.ShowText("Notificación", "No hay cambios que guardar.");
            return;
        }

        if (grid.Validate() != true) {
            return;
        }

        if (mandName === "DISCARD_CHANGES") {
        var callback = function () {
            var innerGrid = arguments.callee.Grid;

            innerGrid.AddedEntities = [];
            innerGrid.DeletedEntities = [];
            innerGrid.Databind(innerGrid.OriginalEntities);

            jQuery(innerGrid.Root).attr("class", "");
            delete window.ModifiedGrids[innerGrid.Name];

            Exertus.MainModalPanel.ShowText("Notificación", "Se han descartado los cambios.");
        }

        var grid = window.RegisteredControls.Grids.Artículos;
        callback.Grid = grid;
        Exertus.MainModalPanel.Confirm("Confirmación", "¿Confirma que desea descartar los cambios?", callback);
    }

    if (mandName === "CANCELAR") {
        var callback = function () {
            var innerGrid = arguments.callee.Grid;

            innerGrid.AddedEntities = [];
            innerGrid.DeletedEntities = [];
            innerGrid.Databind(innerGrid.OriginalEntities);

            jQuery(innerGrid.Root).attr("class", "");
            delete window.ModifiedGrids[innerGrid.Name];

            Exertus.MainModalPanel.ShowText("Notificación", "Se han cancelado los cambios.");
        }

        var grid = window.RegisteredControls.Grids["Carga De Archivos"];
        callback.Grid = grid;
        Exertus.MainModalPanel.Confirm("Confirmación", "¿Confirma que desea cancelar los cambios?", callback);
    }

}

The error is marked in the first line, the very firs that is empty, so I don't know what that could be.

My other problem is that Chrome says I have not defined a function, but I alreadyd have it defined in all of my documents in which it needs to be defined, could you guys please tell me if there's any tool that would help me find out where it is not defined? Thanks!

so I have this unexpected end of input in my JS, it is in line 1 and I really can't understand what is it, here's the code:

window.HandlePageCommand = function (mandName) {

    document.getElementById("buffer").innerHTML = mandName + " | " + window.ActiveForm.Name;
    var activeForm = window.ActiveForm;
    var call;
    var callback;
    var requestData;
    var grid;

    if (mandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (mandName === "ADD_PERIOD") {

        target = activeForm.Sections[1];
        window.SelectedState = {};
        activeForm.BindUI(window.SelectedState);
        grid = window.RegisteredControls.Grids["Semestres"];

        grid.AddedEntities = [];
        grid.DeletedEntities = [];
        grid.Databind([]);
        Exertus.MainModalPanel.Show("Detalle", target);
        return;
    }

    if (mandName === "ADD_MATERIAL") {

        target = activeForm.Sections[1];
        window.SelectedState = {};
        activeForm.BindUI(window.SelectedState);
        grid = window.RegisteredControls.Grids["GRID_DE_MATERIALES"];

        grid.AddedEntities = [];
        grid.DeletedEntities = [];
        grid.Databind([]);
        Exertus.MainModalPanel.Show("DETAIL", target);
        return;
    }


    if (activeForm.Name === "Periodos") {

        callback = function (responseData) {
            var innerGrid = window.RegisteredControls.Grids["Semestres"];
            var responseInfo = jQuery.parseJSON(responseData);
            innerGrid.Databind(responseInfo.Users);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }

        if (window.ActiveForm.Validate() != true) {
            return;
        }

        window.SetLoading(true);
        call = new Exertus.ServerCall("MainWebModule");
        this.SelectedPeriod = this.SelectedPeriod || {};
        activeForm.BindEntity(this.SelectedPeriod);
        grid = window.RegisteredControls.Grids["Semestres"];

        requestData = {
            PeriodData: this.SelectedPeriod
        }
        call.Execute("SavePeriodChanges", requestData, callback);
        return;

    }

    if (mandName === "GUARDAR") {

        if (activeForm.Name === "Factores de Venta 1") {
            var callback = function (responseData) {
                window.OriginalFactors = jQuery.extend({}, window.FactorsInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.FactorsInfo = window.FactorsInfo || {};
            activeForm.BindEntity(window.FactorsInfo);
            call.Execute("SaveFactors", window.FactorsInfo, callback);
            return;
        }


            if (mandName === "SAVE") {

        if (activeForm.Name === "Direcciones") {
            var callback = function (responseData) {
                window.OriginalAddress = jQuery.extend({}, window.AddressInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.AddressInfo = window.AddressInfo || {};
            activeForm.BindEntity(window.AddressInfo);
            call.Execute("SaveAddress", window.AddressInfo, callback);
            return;
        }

            if (mandName === "SAVE") {

        if (activeForm.Name === "Materiales") {
            var callback = function (responseData) {
                window.OriginalMaterials = jQuery.extend({}, window.MaterialsInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.MaterialsInfo = window.MaterialsInfo || {};
            activeForm.BindEntity(window.MaterialsInfo);
            call.Execute("SaveMaterials", window.MaterialsInfo, callback);
            return;
        }

    if (mandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (mandName === "GUARDAR") {

        if (activeForm.Name === "Factores de Venta 2") {
            var callback = function (responseData) {
                window.OriginalFactorsBoundaries = jQuery.extend({}, window.FactorsBoundariesInfo);
                window.SetLoading(false);
                Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
            }

            if (window.ActiveForm.Validate() != true) {
                return;
            }

            window.SetLoading(true);
            var call = new Exertus.ServerCall("MainWebModule");
            window.FactorsBoundariesInfo = window.FactorsBoundariesInfo || {};
            activeForm.BindEntity(window.FactorsBoundariesInfo);
            call.Execute("SaveFactors", window.FactorsBoundariesInfo, callback);
            return;
        }

    if (mandName === "CANCEL") {
        Exertus.MainModalPanel.Hide();
        return;
    }

    if (mandName === "SAVE_CHANGES") {
        var callback = function (responseData) {
            var innerGrid = arguments.callee.Grid;
            var entities = jQuery.parseJSON(responseData);
            window.FamilyProductsTypes = entities;

            innerGrid.AddedEntities = [];
            innerGrid.ModifiedEntities = {};
            innerGrid.DeletedEntities = [];

            innerGrid.Databind(entities);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }


        var grid = window.RegisteredControls.Grids["Artículos"];

        if (grid.HasChanges() != true) {
            Exertus.MainModalPanel.ShowText("Notificación", "No hay cambios que guardar.");
            return;
        }

        if (grid.Validate() != true) {
            return;
        }

        if (mandName === "DISCARD_CHANGES") {
        var callback = function () {
            var innerGrid = arguments.callee.Grid;

            innerGrid.AddedEntities = [];
            innerGrid.DeletedEntities = [];
            innerGrid.Databind(innerGrid.OriginalEntities);

            jQuery(innerGrid.Root).attr("class", "");
            delete window.ModifiedGrids[innerGrid.Name];

            Exertus.MainModalPanel.ShowText("Notificación", "Se han descartado los cambios.");
        }

        var grid = window.RegisteredControls.Grids.Artículos;
        callback.Grid = grid;
        Exertus.MainModalPanel.Confirm("Confirmación", "¿Confirma que desea descartar los cambios?", callback);
    }

    if (mandName === "CANCELAR") {
        var callback = function () {
            var innerGrid = arguments.callee.Grid;

            innerGrid.AddedEntities = [];
            innerGrid.DeletedEntities = [];
            innerGrid.Databind(innerGrid.OriginalEntities);

            jQuery(innerGrid.Root).attr("class", "");
            delete window.ModifiedGrids[innerGrid.Name];

            Exertus.MainModalPanel.ShowText("Notificación", "Se han cancelado los cambios.");
        }

        var grid = window.RegisteredControls.Grids["Carga De Archivos"];
        callback.Grid = grid;
        Exertus.MainModalPanel.Confirm("Confirmación", "¿Confirma que desea cancelar los cambios?", callback);
    }

}

The error is marked in the first line, the very firs that is empty, so I don't know what that could be.

My other problem is that Chrome says I have not defined a function, but I alreadyd have it defined in all of my documents in which it needs to be defined, could you guys please tell me if there's any tool that would help me find out where it is not defined? Thanks!

Share Improve this question edited Aug 12, 2013 at 23:34 Jonathan Lonowski 124k34 gold badges202 silver badges202 bronze badges asked Aug 12, 2013 at 23:23 Nath AviñaNath Aviña 311 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

For all of the { in the snippet, it's missing around 5 }.

This creates a SyntaxError as the parser is trying to match up each pair and runs out of code before it can (thus, "unexpected end"). This error also voids the function definition, which is why it doesn't exist for other code that might try to use it.

For tools to help, you might try JSHint. It can be somewhat stringent, but will scan a snippet of code and note any suggestions it thinks will help. And, it is configurable, so scan through the checkbox list to adjust the types of warnings it gives.

Though, best guess is that they start missing with:

if (mandName === "GUARDAR") {

    if (activeForm.Name === "Factores de Venta 1") {
        var callback = function (responseData) {
            window.OriginalFactors = jQuery.extend({}, window.FactorsInfo);
            window.SetLoading(false);
            Exertus.MainModalPanel.ShowText("Notificación", "Se han guardado los cambios.");
        }

        if (window.ActiveForm.Validate() != true) {
            return;
        }

        window.SetLoading(true);
        var call = new Exertus.ServerCall("MainWebModule");
        window.FactorsInfo = window.FactorsInfo || {};
        activeForm.BindEntity(window.FactorsInfo);
        call.Execute("SaveFactors", window.FactorsInfo, callback);
        return;
    }

//} <-- missing

I think you forgot one parenthesis, look at the code near:

if (mandName === "DISCARD_CHANGES") {
var callback = function () {

There is no closing } for the if statement as far as I can see.

本文标签: javascriptUnexpected end of input (Line 1) and Undefined FunctionStack Overflow