2015-09-22 125 views
0

似乎有這樣的事情,但在opposite。這是closest但我沒有存儲任何東西。發送客戶端變量到服務器流星

我只使用條紋在支付我在其他post/answer

客戶:

我抓的價值,用jQuery,從輸入字段:

<input type="text" id="amount" name="amount"/> 
var amount = $("#amount").val() *100; // the js client 

服務器:

要給該卡充電,你應該有這樣的:

amount: 7000, // I want to remove the static value 

我需要的是這樣的:

amount: amount 

我仍然在學習js和我想的jQuery的工作,但我想不會。我試過將amount傳遞給isServer函數,但這不起作用。任何替代品?

我也試過用var amount = document.getElementById('#amount');但是document沒有定義。

編輯:

if (Meteor.isServer) { 
    Meteor.methods({ 
    'chargeCard': function(stripeToken, amount) { 
     check(stripeToken, Object); 
     var stripe = Meteor.npmRequire('stripe')('sk_test_rand'); 

     stripe.customers.create({ 
     email: '[email protected]' 
     }).then(function() { 
     return stripe.charges.create({ 
      amount: amount, 
      currency: 'gbp', 
      source: stripeToken.id 
     }); 
     }).then(function(err, charge) { 
     // New charge created on a new customer 
     console.log(err, charge); 
     }, function(err) { 
     // Deal with an error 
     console.log('Card not charge') 
     }); 
    } 
    }); 
} 
+0

任何特定的錯誤?你可以給你完整的jQuery代碼,你正在調用isServer函數。如果您還可以提及服務器端代碼,那將會很棒。 –

+0

@Sylar http://docs.meteor.com/#/full/meteor_methods'流星的方法' –

+0

我已編輯帖子。 @MarkUretsky我會讀一讀。謝謝。 – Sylar

回答

0

撥叫您需要使用meteor.call客戶端服務器上的流星方法:

Meteor.call('chargeCard', token, amount, function (err, res) { 
    if (err) { 
    console.log(err); 
    return; 
    } 
    // success 
    // if you return anything from the server you can find it with res 
    console.log(res); 
}); 
相關問題