Poh Zi How
Poh Zi How

Reputation: 1569

Meteor method not working properly in mozilla

I am trying to make a call to a meteor method, to insert a document before redirecting the user to the relevant url (using the generated document _id).

The code currently works on chromium but not on firefox, where on firefox it appears to just get redirected right away without actually inserting anything.

I've attached my code at the bottom. Can anyone tell me what went wrong and what can I do to fix it? Why will chrome and firefox behave differently in this situation?

Any help provided is greatly appreciated!

client.js

newDoc(){
    Meteor.call('addDoc',{
      // some parameters
    })
  }

clientandserver.js (Meteor method)

'addDoc'(obj){
    console.log(obj); // does not output anything on firefox
    DocumentData.insert({
      //some parameters
    },function(err,documentID){
      if (Meteor.isClient){
        window.location = '/docs/' + documentID;
        // redirection happens before insertion on firefox
      }
    });
  }

Upvotes: 0

Views: 57

Answers (1)

Mostafiz Rahman
Mostafiz Rahman

Reputation: 8552

Bring window.location to the client side. Like:

newDoc(){
   Meteor.call('addDoc', data, function(error, result){
     if(result){
        window.location = '/docs/' + documentID;
     }
  })
}

And put only the insertion in server side, like:

'addDoc'(obj){
    return DocumentData.insert({
      //some parameters
    });
  }

I've used this structure and it works for me in both Firefox & Chrome.

Upvotes: 1

Related Questions