1

I would like to use the same alert message to display all the messages at once.

function LoadData(obj) {
    var ArrayData = $('input[type="hidden"][id^="li"]').map(function() {
        return this.getAttribute("value");
    }).get();

    $.ajax({
        data: {
            GUID: JSON.stringify(ArrayData)
        },
        url: "/LoadOrder/LoadData",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function(result) {
            if (result.length > 0) {
                for (var item of result) {
                    alert("There are problems with your selections ${item.Desc} and ${item.EDesc}
.");
                }
            }
        }
    });
}

Expected result should be displayed like below only once.

Currently, the same message displays 3 times.

There are problems with your selections.

ABC - CDE

GFE- Test

Test1 - Test2

Is there any way to display all in once.

1 Answer 1

1

You could change the success callback so that you first create the list of messages as a string and then call the alert

success: function(result) {
  if (result.length > 0) {
    const problems = result.map(item => `${item.Desc} - ${item.EDesc}`).join('\n');
    alert(`There are problems with your selections.\n${problems}`);
  }
}

and without using arrow functions

success: function(result) {
  if (result.length > 0) {
    var problems = result.map(function(item) {
      return `${item.Desc} - ${item.EDesc}`
    }).join('\n');
    alert(`There are problems with your selections.\n${problems}`);
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Gabriele Petroli, Can you please use normal function to support in IE. This arrow function does not support in IE
@testtest sure, added a version without using arrow functions.

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.