2016-03-18 32 views
-1
使用AJAX的紅寶石數據

你好我已經包含在我看來無法張貼在軌道上

= form_for @order, :url => update_express_shipping_path,:remote=> true, :html => { :id => "shippingDetails" } do |form| 
    = form.radio_button :express_shipping, true, :value => true, :id => 'shipping_method4', :name => 'shipping_method' 
    Express Shipping 
    .checkOrder{:value=> @order.id} 

,並在我的js文件中給出的代碼inlcuded

$('#shipping_method4').click(function(){ 
    if($(this).is(':checked')){ 
     alert ('123') 
     $.ajax({ 
      url: '/update_express_shipping', 
      type: 'POST', 
      data: { 
       'id': $('.checkOrder').attr('value'), 
       'express_shipping': $(this).val() 
       }, 
      contentType: 'json' 
     });  
    } 
}) 

,並在我的控制器

def update_express_shipping 
    byebug 
    a = '123' 
    end 

現在,當我單擊單選按鈕,它被選中,所以我沒有收到我的控制器中的數據,它只給出了這個 params {「controller」=>「spree/checkout」,「action」=>「update_express_shipping」}

請讓我知道我錯在哪裏。提前致謝。

+0

以下語法,你可以請把日誌 –

回答

1

單選按鈕,你應該使用的變化()而不是點擊()

更換

$( '#shipping_method4')。點擊(函數(){

$( '#shipping_method4')。改變(函數(){

+0

沒有它不是與此也 – railslearner

+0

工作也只添加一個單選按鈕或一個以上。 表單必須有多個單選按鈕。 如果您只添加一個。你必須要添加複選框而不是單選按鈕。 隨着你的回覆,我可以幫助你更好。 – krazedkrish

1

您可以嘗試的$.post

$.post('/update_express_shipping', { 'id': $('.checkOrder').attr('value'), 
       'express_shipping': $(this).val()})