Within a textarea, users input one or more email addresses separated by commas.
Here is my JavaScript code:
var emails = $("#emails").val().split(",");
if (emails.length == 0)
{
window.alert("Please enter an email address.");
$("#emails").focus();
return;
}
var valid = validateEmails(emails);
var goodEmails = valid[0];
var badEmails = valid[1];
var json = JSON.stringify(goodEmails);
$.ajax
({
url: "/mfa/service/initiate_user",
type: "POST",
data: {"emails" : json},
The resulting data:
["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfc6ded0ffde91dcd0d2">[email protected]</a>","<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5ccd4daf5d79bd6dad8">[email protected]</a>]
Desired outcome:
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f667e705f7e317c7072">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94edf5fbd4f6baf7fbf9">[email protected]</a>
To handle this in the backend, I would remove the brackets and quotes from each email.
What is the recommended method to send emails to the backend without including unnecessary brackets and quotes?