I have developed an application that utilizes JSON
to send messages through ajax
. Here is the JavaScript object used for this purpose:
var message = {
"message_by": colmn[0].innerHTML,
"message_date": new Date(),
"message_recipients": [
{
"phone_number": colmn[1].innerHTML,
"recipient_name": colmn[2].innerHTML
}
],
"message_text": colmn[3].innerHTML,
"subscriber_name": "John Doe"
};
The sending process involves posting the message like this:
var url = "http://url/api/sendMessage";
$.ajax({
type: "POST",
url: url,
data: JSON.stringify(message),
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (data, status, jqXHR) {
console.log(data);
console.log(status);
console.log(jqXHR);
alert("Success. Message sent.");
},
error: function (xhr) {
alert("Error. Try again.");
}
});
An example of a stringified
message could be structured as follows:
var message = {
"message_by": "Brian",
"message_date": new Date(),
"message_recipients": [{
"phone_number": "0700111222",
"recipient_name": "Timothy"
}, {
"phone_number": "0800222111",
"recipient_name": "Winnie"
}],
"message_text": "Hello! You are invited for a cocktail at our auditorium. ",
"subscriber_name": "John Doe"
}
However, I encountered an issue where messages with more than 100 recipients were failing to post to the API. Strangely, messages with up to 99 recipients worked fine. My colleague mentioned that there were no restrictions on the API's end.
Is there a way to limit the object size to 99 recipients and push the excess recipients to a new object while still maintaining them within the same ajax post request? Are there any creative solutions to overcome this limitation?