我有js文件:
$('#some_btn').click(function() {
var valuesToSubmit = $('#some_form').serialize();
var url = $('#some_form').attr('action');
console.log("VALUE: " + valuesToSubmit);
console.log("URL: " + search_url);
$.ajax({
type: 'POST',
url: url, //sumbits it to the given url of the form
data: valuesToSubmit,
dataType: "JSON",
success: function(data) {
console.log("saved");
console.log(data);
}
});
return false;
});
响应的控制器动作:
def some_action()
...
@response = {resp: "ack"}
respond_with @response do |format|
format.json { render :layout => false, :text => @response }
end
end
路线:
post '/abc/some_action', to: 'abc#some_action'
但执行后我收到:
ArgumentError
Nil location provided. Can't build URI.
@response = {resp: "ack"}
respond_with @response do |format| # <--- Error here
format.json { render :layout => false, :text => @response }
end