English 中文(简体)
铁路和jQuery Ajax(POST) - 错误反应
原标题:Rails and jQuery Ajax (POST) - error response

我在建铁路应用程序,我想和jj 查询做AJAX电话。当我打AJAX电话(POST)时,我的方法有误。但是我不知道问题是什么:

当我使用 GET 方法时, 一切工作都正常, 但是当我把它换成 POST 时, 我就会收到错误( 是的, 我改变了路线. rb : ) ) 。

jj 查询

$.ajax({
  url: "/login/checkLogin/",
  dataType: "json",
  data: data,
  type:  post ,
}).done(function(response){
  console.log(response);
})

方法方法方法

ldap = Net::LDAP.new
ldap.host = "***"
ldap.port = ***
ldap.auth %[#{params[:login_username]}], params[:login_password]

if ldap.bind
 session[ loggedin ] = true
 respond_with "1".to_json
else
 session[ loggedin ] = false
 respond_with "0".to_json
end

错误消息( 来自控制台)

undefined method `"0"_url 

谢谢 谢谢

最佳回答

It is backside of Rails magic :) By default, Rails uses ActionController::Responder to process respond_with if no block given 或 template is not available. F或 POST method (REST create ) and non-html f或mats like xml and json, it generates a response with encoded resource, status code (:success), and resource location. So it tries to find out the URI of the resource you have passed, and fails on this step.

只需通过 : place {gt; non 选项以取代默认值, 或者使用明确的 repond_to

respond_with "0".to_json, :location => nil

respond_to do |f或mat|
  f或mat.json {render :json => "0".to_json}
end
问题回答

尝试设置 contentType: " application/json; charset=utf-8, "/code> $.ajax ({...})





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...