0

Hello,

I am receiving this error message while trying to process the following javascript - "Error, the configuration is failed to save".

What might be wrong? How to troubleshoot the javascript?

partial/setting.blade.php

   function onSave(el) {

    var parent = $(el).closest("li");
    var form = $(parent).find("form");
    var editel = $(parent).find(".edit_form");
    var beforeText = $(parent).find(".setting-nav2").html();
    var options = {
        beforeSubmit: function () {
            var parent = $(el).closest("li");
            var loading_gif = "<img width='24px' src='{{url('')}}/images/loading.gif'/>"
            $(parent).find(".setting-nav2").html(loading_gif);
        },
        success: function (data) {
            $(editel).find("strong").html(data.message);
            cancel(parent);
            pesanOk("Configuration is saved successfully");
        },
        error: function (data) {

            try {
                var message = JSON.parse(data.responseText);
                if (message.message != "") {
                    pesanErr(message.message);
                } else  pesanErr("Error, the configuration is failed to save");
            } catch (ec) {
                console.log(data);
                pesanErr("Error, the configuration is failed to save");
            }

            $(parent).find(".setting-nav2").html(beforeText);

        }
    };

    $(form).ajaxSubmit(options);
}
2
Contributors
3
Replies
36
Views
3 Months
Discussion Span
Last Post by pixelsoul
0

You have a few different syntax errors in that code. Get into the habit of running your JavaScript through JSLint when you're having issues. It can save you time.

Redefinition of 'parent' from line 1.

var parent = $(el).closest("li");

8.88Expected ';' and instead saw '$'.

var loading_gif = "<img width='24px' src='{{url('')}}/images/loading.gif'/>"

21.24Expected '{' and instead saw 'pesanErr'.

} else  pesanErr("Error, the configuration is failed to save");
0

How to fix the whole js codes:

Well, seeing what's recommended in the JsLint this is what I fix:

var parent = $(el).closest("li"); // I do not know how to fix this one

Next

var loading_gif = "<img width='24px' src='{{url('')}}/images/loading.gif'/>";

And

    } else { pesanErr("Error, the configuration is failed to save");}

And I am still facing the same error.

Edited by davy_yg

0

To be fair, it isn't a JS error, it's a message that you're outputting when message.message is an empty string, and you're outputting that same message in your catch statement as well.

I would remove the one in the catch statement and see if it still occurs, and also check to see what your console displays, since you're outputting to the console data which is being passed to the function.

If you're still getting that message, then I would assume that message.message is an empty string, the code is working as expected, and you'll need to troubleshoot why it's returning an empty string.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.