我在Rails应用程序中使用ajax。在我的应用程序的js我有在Rails 4中不执行Ajax响应
$('#request_name').on('focusout', function() {
var clientName = $(this).val();
$.ajax({
\t url: "/requests/autofill/"+clientName,
\t type: "GET",
\t contentType: 'text/javascript'
\t });
所以我发送Ajax请求,请求控制器动作自动填充。
自动填充方法:
def autofill
@client = Client.where("name=?",params[:name]).take
\t respond_to do |format|
\t format.js
\t format.html
\t end
end
alert("hello");
$('#request_mobile").val('hi there'); \t
alert("hello");
$('#request_mobile").val('hi there');
但没有任何反应,甚至警报未启动。我不知道我做错了什么?
你能用'ajax'请求显示一些日志文件吗? – 2015-03-19 08:52:10
@Зелёный,开始GET“/ requests/autofill/Jordane%20Koch”:: 1在2015-03-19 14:39:19 +0600 通过RequestsController处理#autofill as */* 参数:{“name” (“Jordane Koch”)限制1 已提交的请求/ autofill.js.erb(0.1ms) 已完成在11ms内200 OK(查看:7.6ms | ActiveRecord:0.4ms)。这是你问的吗? – yerassyl 2015-03-19 08:54:49