0
votes

When saving a model to a Node.js endpoint I'm not getting a success or error response every time, particularly on the first the first save and then sometimes on other attempts. The Node.js server is sending a success response every time, and if I use a Chrome rest client it works every time.

var mailchimpModel = new MailchimpModel();
var data = {
    "email": $('#email').val()
}
mailchimpModel.save(data, {
    success: function(model, response) {
        console.log("success");
        console.log(response);
    },
    error: function(model, response) {
        console.log("error");
    }
});

What I have found is the nodejs server is receiving 2 requests when it's failing

OPTIONS /api/mailchimp 200
POST /api/mailchimp 200

and I only get a success response if I submit the request again straight afterwards.

2
Have you tried to debug the request from Firebug or any other tool that you use. - Gntem

2 Answers

0
votes

It's possible your model is failing client-side validation. To check, try:

console.log(mailchimpModel.save(data));

If the value is false then your model is failing client-side validation (usually defined in a validate function in the model). You can check the errors with

console.log(mailchimpModel.valdiationError);
0
votes

OK found that i need to handle the OPTIONS method on the server, using the soltion on this post worked for me.

https://stackoverflow.com/a/13148080/10644