0
後從jQuery的創建我有表格數據:?如何調用軌道方法成功(函數(JSON)
<div class="container">
<div class="row-fluid">
<%= form_tag class: "form-horizontal" id: "payment-form" %>
<%= hidden_field "card_registration_url", card_preregistration['CardRegistrationURL'] %>
<%= hidden_field "preregistration_data", card_preregistration['PreregistrationData'] %>
<%= hidden_field "access_key", card_preregistration['AccessKey'] %>
<%= hidden_field "id_card", card_preregistration['Id'] %>
<fieldset>
<div id="legend">
<legend class="">Deposit for contract <%= @contract.title %></legend>
</div>
<div id="legend">
<legend class="">Amount <%= @contract.amount %></legend>
</div>
<!-- Name -->
<div class="control-group">
<%= label "card_holder", "Card Holder's Name", class:"control-label" %>
<div class="controls">
<%= text_field_tag "card_holder", { id: "username", class: "input-xlarge"} %>
</div>
</div>
<!-- Card Number -->
<div class="control-group">
<%= label "card_number", "Card number", class:"control-label" %>
<div class="controls">
<%= text_field_tag "card_number", { id: "card_number", class: "input-xlarge"} %>
</div>
</div>
<!-- Expiry-->
<div class="control-group">
<%= label "expity_date", "Card Expiry Date", class:"control-label" %>
<div class="controls">
<%= text_field_tag "card_expiration_date", { id: "card_expiration_date", class: "input-xlarge"} %>
</div>
</div>
<!-- CVV -->
<div class="control-group">
<%= label "cvv", "Card CVV", class:"control-label" %>
<div class="controls">
<input type="password" id="card_cvx" name="password_confirm" placeholder="" class="span2">
<%= text_field_tag "card_expiration_date", { id: "card_expiration_date", class: "input-xlarge"} %>
</div>
</div>
<!-- Save card -->
<div class="control-group">
<div class="controls">
<label class="checkbox" for="save_card">
<%= label "save_card", class:"check_box" %>
<input type="checkbox" id="save_card" value="option1">
Save card on file?
</label>
</div>
</div>
<!-- Submit -->
<div class="control-group">
<div class="controls">
<%= button_tag "Pay now", remote: true, class: "btn btn-success" id="process" %>
</div>
</div>
</fieldset>
<% end %>
</div>
</div>
我從表格數據發送到服務器支付系統(在我的例子它hidden_field「 card_registration_url「),通過郵寄方法
register_card.js
$('#process').click(function(){
var valuesToSubmit = $('#payment-form').serialize();
console.log(valueToSubmit);
$.ajax({
url: $('#mail-form').attr('action'), //sumbits it to the given url of the form
data: valuesToSubmit['card_registration_url'],
dataType: "JSON" // you want a difference between normal and ajax-calls, and json is standard
}).success(function(json){
//act on result.
});
return false; // prevents normal behaviour
});
如果從服務器響應都很好,需要調用動作payments_con troller /創建完整付款。
我如何調用操作payments_controller/create?
你好@ dev85,你試過了嗎? – Sravan
時刻,懇求。我在嘗試.... – dev85