小编use*_*030的帖子

AJAX成功函数未被调用

我试图从AJAX调用获取成功函数到fire.我知道它正常工作,因为我正在使用自己的API,我可以看到它正确地访问了URL并且服务器正在输出HTTP 200.

我认为这是因为服务器正在输出json,所以我试图在AJAX调用中考虑到这一点,但仍然成功函数不起作用.这是我的代码

阿贾克斯

$.ajax('http://localhost:3000/api/users/show/:id', {
  type: 'GET',
  dataType: 'json',
  contentType: "application/json",
  data: {
    id: 1
  },
  success: function(response) {
    return alert("Hey");
  }
});
Run Code Online (Sandbox Code Playgroud)

api方法

class UsersController < ApplicationController
    respond_to :json

    def show
        respond_with User.find(params[:id])
    end

end
Run Code Online (Sandbox Code Playgroud)

服务器日志

Started GET "/api/users/show/:id?id=1" for 127.0.0.1 at 2013-08-02 20:36:42 -0700
Processing by MainController#index as JSON
  Parameters: {"id"=>"1", "path"=>"api/users/show/:id", "main"=>{}}
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 1]]
  Rendered main/index.html.erb within layouts/application (0.6ms)
Completed 200 OK in …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery ruby-on-rails

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

ruby-on-rails ×1