2014-11-23 23 views
1

我的Js和AJAX代碼有什麼問題?我在select_tag上使用ajax和JS,並且出現ajax錯誤;select_taf上的Ajax和JS; SyntaxError:missing}屬性列表後

- @departments = @collocation_request.collocation_request_departments 

td Reviewer 
     - @departments.each do |department| 
      td 
       div.input-append 
       = select_tag :reviewer_id, options_from_collection_for_select(User.where(department_id:     department.department_id), "id","full_name"), prompt: 'Select a Reviewer', remote: true 

    javascript: 
      $(function(){ 
        $(document).on('change','#reviewer_id',function(e) { 
            alert($(this).val()); 
       var collocation_request_id = $(this).data('collocation-request-id'); 
       var departments_id = $(this).data('department-id'); 
       jQuery.ajax({ 
              type: "PUT", 
              dataType: 'JSON', 
              data: {collocation_request_department: {reviewer: $(this).val()}, 
        url: '/collocation_requests/'+collocation_request_id+'/departments/'+departments_id+'.js' 
       }).complete(function(data, textStatus, jqXHR) { 
       window.location = window.location; 
            }); 
          }); 
      }); 
+0

你得到,上面寫着「缺}」,因爲你的代碼丟失的錯誤是「}」上的「數據:」行了ajax參數。什麼不清楚? – Pointy 2014-11-23 03:19:19

+0

我添加了缺少的部分。 JS正在工作,但PUT功能不是。不知道爲什麼 – Kourosh 2014-11-23 11:05:39

回答

1

數據添加}

data: {collocation_request_department: {reviewer: $(this).val()}}, 
+0

謝謝,它的工作。 – Kourosh 2014-11-23 05:50:52

+0

Anik:JS和AJAX正在工作,但是PUT函數沒有,這裏是代碼的其他部分: – Kourosh 2014-11-23 10:52:52

+0

不能在這裏添加代碼,我得到errores – Kourosh 2014-11-23 11:00:01

相關問題