Ajax response is null

Ajax response is null

本文关键字:null is response Ajax      更新时间:2023-09-26

我有一个AJAX调用,它与我的Rails控制器对话,AJAX可以,但回调不包含任何数据。

我的AJAX调用:

$.ajax({
    url: '/get_progress/:' + this.props.myfile,
    type: "GET",
    dataType: "text",
    success: function(data) {
        console.log(data);
    }.bind(this),
    error: function(data) {
        console.log("Error");
    }.bind(this)
});

我的轨道控制器方法:

def get_progress
    a = Rails.configuration.progress
    render :text => a
end

我的路线:

get '/get_progress/:id' => 'myfiles#get_progress'

我的AJAX Success回调中没有数据,为什么我的a值没有返回?

您的url不正确,:id只是ID:的

$.ajax({
    url: '/get_progress/' + this.props.myfile,
    type: "GET",
    dataType: "text",
    success: function(data) {
        console.log(data);
    },
    error: function(data) {
        console.log("Error");
    }
});