0

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.

dottodot
  • 1,479
  • 1
  • 16
  • 24

2 Answers2

0

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);
David Sulc
  • 25,946
  • 3
  • 52
  • 54
0

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

Community
  • 1
  • 1
dottodot
  • 1,479
  • 1
  • 16
  • 24