MeteorJS unexpected behaviour when calling server methods

71 Views Asked by At

Some how sequence or delay on server calls brings different behaviour. Code should explain this more clearly.

let editProfile = function (e) {
  e.preventDefault();

  let info = {};
  info.username = $(".editProfile #usernameInput").val();
  info.email = $(".editProfile #emailInput").val();

  let picture = $(".editProfile #imageInput")[0].files[0]; 
  if (picture) {                               <-|
    Images.insert(picture);                      |Problem
  }                                              |
  Meteor.call("editProfile", this, info);      <-|
};

this works fine but when I try to change the sequence of these calls I get error in the console.

  Meteor.call("editProfile", this, info);      <-|
  if (picture) {                                 |Error is given
    Images.insert(picture);                      |
  }                                            <-|

Error in browser:

Failed to load resource: the server responded with a status of 404 (Not Found)

Error: "Queue" failed [404] Not Found [404] [undefined], Error: failed [404] Not Found [404] [undefined] at cfs_upload-http.js:351 at cfs_upload-http.js:77 at underscore.js:750 at XMLHttpRequest.xhr.onreadystatechange (cfs_upload-http.js:200)

If I try to do something like this: (no error is given)

Meteor.call("editProfile", this, info);
setTimeout(function () {
  if (picture) {
    Images.insert(picture);
  }
},2000);

I would really like to know why this behaviour is affected by timeouts/sequence.

0

There are 0 best solutions below