2013-02-27 32 views
2

使用流星0.5.7 - 遵循派對示例 - 製作了客戶端,服務器文件夾,並在其中放置了相應的client.js和server.js文件。我有自動發佈,不安全刪除,並添加電子郵件包。我無法讓Meteor.call啓動,調試顯示它被繞過,我鬆散地遵循這一點 - 我還是不明白。無法從MeteorJS中的客戶端調用Meteor.call?

// server.js 
Meteor.startup(function() { 
    process.env.MAIL_URL = '...'; // using mailgun URL 
}); 

Meteor.methods({ 
    call_me: function (options) { 
    var options = options || {}; 
    Email.send({ 
     from: options.from, 
     to: options.to, 
     replyTo: options.from || undefined, 
     subject: options.subj, 
     text: options.msg, 
    }); 
    }, 
}); 

// client.js 
Template.form.events({ 
'click .submit' : function (event, template) { 
    var from = template.find("#from").value; 
    var to = template.find("#to").value; 
    var subj = template.find("#subj").value; 
    var msg = template.find("#msg").value; 
    var options = { from: from, to: to, subj: subj, msg:msg }; 

    Meteor.call('call_me', options, function(err, data) { 
    if (err) 
    console.log(err); 
    }); 
} 
}); 

// client.html - the gist of it 
<body> 
    {{> page }} 
</body> 
<template name="page"> 
    {{> form }} 
</template> 
<template name="form"> 
    <form .... 
</template> 

最後,我確實有Meteor.methods({...});坐在客戶端/服務器文件夾之外的model.js文件中 - 並且它仍然不會觸發電子郵件或調用Meteor.call方法。我有點想把我的頭包裹在前面提到的附加鏈接中的一個存根的概念中,將這個調用包裝在一個函數中並調用它,但我仍然沒有得到任何活動。感謝您的任何建議。

+0

你在'localhost'上開發嗎?如果是這樣,'Email.send'不會發送電子郵件,它會將電子郵件打印到您的控制檯(例如終端) – Rahul 2013-02-27 19:11:25

+0

我正在本地主機上開發,但電子郵件不打印到控制檯(術語/網絡) - 我放置了調試器;在Meteor.call函數中,它甚至沒有調用它。 Hrm,Chrome檢查沒有提供錯誤,但Firefox做到了 - 「[17:30:25.585] POST http:// localhost:3000/sockjs/566/hkevinpk/xhr_send [HTTP/1.1 404 Not Found 2ms]」 - 不知道這意味着什麼,但也許是我會進一步研究的一條線索。 – gamengineers 2013-02-27 22:31:42

+1

你的流星調用和Meteor.methods看起來不錯。請在github上發佈實際文件的要點,我們將能夠更好地協助。 – Dror 2013-02-27 22:51:51

回答

1

嘗試了你的要點。刪除<form>標記並註釋掉Process.env.MAIL_URL做到了。 <form>標記阻止事件觸發器按鈕單擊。