I have a Google Chrome extension (browser action) that sends popup form inputs to my Meteor website/app database. (Based on Log in to a meteor app from a Google chrome extension.)
The XHR code on popup.js:
$(document).ready(function() {
$('#form').on('click','#submitForm',function () {
var xhr = new XMLHttpRequest();
var data = {
"field1": $('#input1').val(),
"field2":$('#input2').val(),
};
xhr.open("POST", "http://MYAPPNAME.meteor.com/extension/post", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify(data));
});
});
The code works very sporadically. Typically on the fourth attempt (i.e., four submissions of the form).
What could be causing this inconsistency? Is it simply a facet of the slow free hosting on meteor.com? I will likely but switching to a custom domain (on a paid server), but ideally want to ensure the functionality before payment.
EDIT
I've added event listeners for the XHR errors (from https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest), as per Xan's suggestion.
xhr.addEventListener("progress", updateProgress, false);
xhr.addEventListener("load", transferComplete, false);
xhr.addEventListener("error", transferFailed, false);
xhr.addEventListener("abort", transferCanceled, false);
Each time now, the "abort" (transferCanceled) alert appears. However, the data is still sent correctly occasionally (even with the error alert).
Is this of any note? Are there better ways to be alerted of errors?