流星方法在mozilla中无法正常工作

时间:2017-03-23 04:05:30

标签: javascript meteor cross-browser

我正在尝试调用meteor方法,在将用户重定向到相关url之前插入文档(使用生成的文档_id)。

目前 的代码适用于chrome 但不适用于firefox,在Firefox上,它似乎只是立即重定向,而不会实际插入任何内容。

我在底部附上了我的代码。任何人都可以告诉我出了什么问题,我该怎么做才能解决它?为什么chrome和firefox在这种情况下表现不同?

非常感谢您提供的任何帮助!

client.js

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

clientandserver.js(流星法)

'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
      }
    });
  }

1 个答案:

答案 0 :(得分:2)

window.location带到客户端。像:

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

并且只在服务器端插入,例如:

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

我已经使用过这种结构,它适用于我和Firefox&铬。