Encountering a JavaScript error in IE 11 and below where a closing parenthesis is expected, along with AJAX functionality not functioning properly in IE 11

Within my script, an AJAX call is being made as follows:

(function() {
var setup, validation;
var errorMessage = '';
var errorClass = '';
var element = '';
var errorElement = '';
var allOk = true;
var testTelefon = /^[0-9\-+]{2,40}$/;
var testEpostAdress = /^(?!.{65})\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

(function() {
    setup = {
        init: function() {
            this.initSendForm();
        },

        initSendForm: function() {
            var self = this;

            $('#helpContactForm').submit(function(event) {
                if (allOk) {
                    var formData = self.getFormData();
                    var url = $(this).attr("action");
                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: url,
                        data: formData,
                        success: function(data) {
                            if (data.Success) {
                                self.resetFormData();
                                self.showModal(data);
                            }
                        },
                        error: function(data) {
                            self.showModal(data);
                        }
                    });
                }
                self.hideModal();
                event.preventDefault();
            });
        },

        getFormData: function() {
            var data = {
                'Namn': $('#namn').val(),
                'Email': $('#epost').val(),
                'Telefon': $('#telefon').val(),
                'Fraga': $('#fraga').val()
            };

            return data;
        },

        resetFormData: function() {
            $('#namn').val(''),
                $('#epost').val(''),
                $('#telefon').val(''),
                $('#fraga').val('')

            return true;
        },

...and the code goes on.

This "contact us" form works in all browsers, except IE 11 and below. In IE, when the form is submitted, it prompts the user to download the JSON response instead of showing it in a Bootstrap modal as intended.

The console error in IE is showing a ") expected" message, indicating a syntax error. I have reviewed the code multiple times and could not find any missing parentheses. This issue seems to be specific to IE.

It's possible that there are interrelated problems or something crucial missing in the AJAX request block causing IE to handle the response differently. The parenthesis error might be linked to another issue.

If anyone has insights or suggestions on how to resolve this IE-specific behavior, your help would be greatly appreciated!

Update: The complete code is now consolidated in one file for better visibility. Any further assistance is welcomed.

Answer №1

In the function definition of setErrorMsgAndClass, default parameter values are utilized.

... function (el, errorEl, nameOfClass = '', errorMsg = '') { ... }

Regrettably, default parameters like that are not supported in any version of Internet Explorer. Please check out the Default Parameters Browser Compatibility Table for more information.

One alternative is to use "old style" default parameters as shown below:

var x = function (el, errorEl, nameOfClass, errorMsg) {
  nameOfClass = (typeOf nameOfClass != 'undefined') ? nameOfClass : 'Default Class Name';
  errorMsg = (typeOf errorMsg != 'undefined') ? errorMsg : 'Default Error Message';

  // code
}

x(a,b,c,d); // works
x(a,b); // works using the defaults instead of c/d

Various other methods for handling default parameters exist to ensure older browsers do not encounter issues. These can be found on the rest of the MDN page linked above.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting issues with JSON compatibility within the OnChange event

Initially, I wrote this code to retrieve a single data point. However, I realized that I needed more fields returned when the drop-down select menu triggered an onchange event. So, I switched to using JSON, but now it's not returning any data. The dro ...

Tips for sending two values to a PHP file using JavaScript Ajax

I have created a code for two dropdown menus. The goal is to select values from both menus and send them to a php file using the GET method. The values should be sent to the php file only when both menus have selections made. Below is the code snippet: ...

Create an AngularJS task manager that saves your to-do list even when the page is refreshed

Currently, I am developing a straightforward to-do list application using AngularJS within an ASP.NET MVC template. Surprisingly, I have successfully integrated Angular and Bootstrap to achieve the desired functionality. The app allows users to add and re ...

Refreshing table cell contents following a table sort operation

I have a dynamic HTML table that retrieves data from MySQL. Every 5 seconds, I use AJAX to check for any changes in the MySQL table and update specific cells in the HTML table. Now, I am interested in incorporating a jQuery plugin for table sorting. You c ...

What is the best way to incorporate "thread.sleep" in an Angular 7 app within a non-async method like ngOnInit()?

Despite the numerous questions and solutions available on Stack Overflow, none of them seem to work when called from a component's init function that is not asynchronous. Here's an example: private delay(ms: number) { return new Promise( ...

Passing an array with pre-defined variables using jQuery's Ajax functionality

Currently, I have a function set up to gather the contents of a form and send it to a PHP page for processing. However, I am facing an issue where no data is reaching the PHP page when sending it via POST or GET methods. function add_new_customer(){ $ ...

Internet Explorer displaying issue with AJAX TabContainer

I am currently working with AJAX Control Toolkit version 15.1, asp.net version 4.5.1 and vs.net 2012 using VB code. All my tools are up-to-date. I have integrated the tabcontainer tool from the AJAX toolkit into my web app and when I test it locally in Chr ...

How can I prevent list items in jQuery Mobile from being truncated with ellipses?

Here is the list I am working with: <ul id="linksList" data-role="listview" data-inset="true" data-filter="true"> <!-- Dynamic contents! --> </ul> This list pulls its data from a local XML file (RSS feed). I am looking f ...

What steps do I need to take to ensure this function runs sequentially? Perhaps my understanding of async and await is lacking

I have a function that is responsible for adding data to my database. However, I'm encountering some inconsistency where it works sometimes and fails other times. My suspicion is that the eDataBuilder function is taking too long to iterate through the ...

Making a request to the Model-View-Controller (M

Can cross-domain ajax be achieved in MVC architecture? Currently, I am using jsonp and it works flawlessly when both sites are on localhost. However, I am unsure if the mvc architecture blocks the jsonp call. <script src="www.example.com"></scrip ...

Error: webpack is failing to load the style and CSS loaders

I'm currently experimenting with the FullCalendar plugin from fullcalendar.io. They recommended using Webpack as a build system, which is new to me. I managed to set up the calendar functionality after some research, but I'm facing issues with th ...

Creating a consolidated System.config mapping for @angular modules using a single .js file

Currently in the process of developing an Angular 2 application, with the specific requirement to consolidate all resulting Javascript files into a single .js file called output.js. Now, the challenge is to incorporate map configuration within System.conf ...

Changing the Displayed Content with a Simple Click of a Link

Layout Overview In the process of developing a tool to streamline work tasks, I want to ensure that I am following best practices. My goal is for the website to initially display only column A, with subsequent columns generated upon clicking links in the ...

The function forEach is unable to handle the process of uploading multiple images to cloudinary

I'm facing an issue with uploading multiple images to Cloudinary from my Vue2JS front-end. I have successfully created a function that uploads a single image, but I am struggling with uploading multiple images using a forEach loop. upload(evt) { ...

Error: The function 'stepUp' was invoked on an object lacking the HTMLInputElement interface during an AJAX request

It's always frustrating to have to ask a question that has already been asked, but I'm having trouble finding a solution that works for me. My issue involves retrieving the value of an input and sending it via AJAX. $("#cell_number").on("change" ...

What is the best way to utilize v-select for searching entries while also allowing users to type in text within the input field for the search?

How can I implement a fold-out display for entries in a v-select field while also enabling text search functionality to find specific items? Are there any Vuetify props that address this, or do you have any suggestions on how to approach this? <v-sele ...

Tips for Utilizing jQuery each Loop

I am attempting to create a foreach loop that will iterate through hidden values on the page, compare them with an external API using Ajax, and display the API results in a < ul > for example. Sample model ITEM1 metavalue (which needs to be che ...

Utilizing Subdirectories in a Command Manager

My goal is to organize my commands into sub folders, but for some reason my bot is not recognizing the commands inside those folders. Strangely, no error message is being displayed. const fs = require('node:fs'); const Discord = require('dis ...

Display the URL with proper formatting in the print function

I am trying to create a table with clickable URLs in a "Link" column, but the URLs are too long and I want to show a custom title instead. So far, I have used the following code: str = "Test Title"; link = str.link("https://my_long_url.com/v1.0/ui/index. ...

Interactive searching with Smalltalk Seaside and jQuery as you type

renderFilterOn: html |aFilter| html textInput onKeyUp: (html jQuery ajax callback: [:val | aFilter := val] value: ((html jQuery this) value); script: [:s | s add: ((s jQuery class: 'itemnames') ...