10

I am trying to build a reusable JavaScript function that makes use of default parameters. However, the IDE warns me I do something wrong.

enter image description here

The code is this:

function standardAjaxRequest(process_script_path, redirect = false) {

    var loading = $(".loading");
    var response_message = $(".response_message");

    // runs the ajax to add the entry submitted
    form.on("submit", function(event) {
        event.preventDefault();

        removeNoticeError();

        var data = form.serialize();

        $.ajax({
            url:      process_script_path,
            type:     "POST",
            dataType: "json",
            data:     data,
            cache:    false,
            success: function(response) {
                if(response.status === false)
                {
                    response_message.addClass("error").text(response.message).fadeIn(1);
                }
                else
                {
                    response_message.addClass("notice").text(response.message).fadeIn(1);
                    if(redirect)
                    {
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    }
                    else
                    {
                        response_content.after(response.content);
                    }

                }
            },
            error: function() {
                response_message.addClass("error").text("There was a problem adding your entry.").fadeIn(1);
            },
            beforeSend: function() {
                toggleLoading();
            },
            complete: function() {
                toggleLoading();
            }
        });
    });
}

I really don't know what is wrong with it? Can you, please, help me understand what's going on?

4
  • Are you using ES6? Commented Jun 1, 2016 at 14:23
  • stackoverflow.com/questions/894860/… Commented Jun 1, 2016 at 14:25
  • I am not sure which one. It's the latest IDE version so, I assume ES6? Commented Jun 1, 2016 at 14:26
  • ES6 is the version of Javascript that adds this feature, not the IDE. Commented Jun 1, 2016 at 14:47

2 Answers 2

11

You can switch the version here:

1. Press CTRL+ALT+S

2 Search for JavaScript & click the select field. and then select ECMAScript 6

View image.

Sign up to request clarification or add additional context in comments.

1 Comment

What does this have to do with the getting the IDE to stop marking the code as an error?
4

In Preferences->Languages & Frameworks->JavaScript, select "ECMAScript 6" from the language version menu to be able to use the new syntax features of ES6.

1 Comment

Useful clarifications, @Barbar. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.