我有一个使用Ajax的客户端请求,最终的URL是/promotion?mtd,日志告诉我参数mtd = null。应该是promo = mtd,我需要在URL中传递的数据。

AJAX:

var promo = document.getElementById('data-select').value;
    $.ajax({
        type: 'GET',
        url: '/promotion',
        data: promo,
        dataType: 'JSON',
        success: function(data){
          alert(data);
        }
    });


日志/development.log:

Started GET "/promotion?mtd" for 127.0.0.1 at 2015-04-14 16:32:34 -0430
Processing by PromosController#get_percent as JSON
  Parameters: {"mtd"=>nil}

最佳答案

var promo = document.getElementById('data-select').value;
    $.ajax({
        type: 'GET',
        url: '/promotion',
        data: {"promo" : promo},
        dataType: 'JSON',
        success: function(data){
          alert(data);
        }
    });

10-07 12:36