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?


   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'/>"
        success: function (data) {
            pesanOk("Configuration is saved successfully");
        error: function (data) {

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



6 Months
Discussion Span
Last Post by pixelsoul

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

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


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


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

And I am still facing the same error.

Edited by davy_yg


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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.