2015-08-29 66 views
0

不工作我已經創建其中select_tag包含onchange函數形式:平變化函數調用Ajax在firefox

形式(advertisments/_form.html.erb):

<div class="controls advertise-medium-select"> 
    <%= select_tag 'advertisment[medium_id]', options_for_select(@mediums.collect { |mid| [mid.name, mid.id] }), :prompt => 'Select Media', onchange: 'get_media_categories()' %> 
</div> 

在我的advertisments.js文件:在這裏,如果我更改select_tag選項,但不打算使用fetch_media_categories方法,則控制檯日誌始終會打印medium

function get_media_categories(){ 
    var medium = $('#advertisment_medium_id option:selected').val(); 
    console.log(medium); 
    $.ajax({ 
     url: '/advertisments/fetch_media_categories', 
     type: 'GET', 
     data: {medium_id: medium} 
    }) 
} 

路線文件:

resources :advertisments do 
    collection do 
     get :fetch_media_categories, :fetch_media_pages 
    end 
    end 

的application.js文件:

//= require jquery 
//= require jquery.easing.1.3 
//= require jquery_ujs 
//= require twitter/bootstrap 
//= require jquery.fancybox.pack 
//= require jquery.fancybox-media 
//= require prettify 
//= require jquery.quicksand 
//= require setting 
//= require jquery.flexslider 
//= require animate 
//= require custom 
//= require pricing_custom 
//= require advertisments 
//= require_tree . 

目前,平變化功能在Chrome的工作,但不是在Firefox(版本39.0)。有人有什麼主意嗎?

回答

0

在advertisment.js

$(function() { 

    $('#advertisment_medium_id').on('change', function() { 
     var medium = $('#advertisment_medium_id option:selected').val(); 
     console.log(medium); 
     $.ajax({ 
      url: '/advertisments/fetch_media_categories', 
      type: 'GET', 
      data: {medium_id: medium} 
     }); 
    }); 

}); 
+0

試試這個仍然沒有工作。 – Emu

+0

@Emu在控制檯中有任何錯誤? –

+1

不,沒有錯誤。我不知道爲什麼,但我已經將控制器ajax移動到另一個控制器,並且它工作正常! – Emu