我正在为我的 Ruby on Rails 网站开发 API,当我尝试使用 jQuery 捕获响应的令牌时遇到问题。使用 Curl 可以正常工作,但在 jQuery 中没有得到任何响应。
Rails 控制器的一部分
render :status => 200, :json => { :token => @user.authentication_token }
使用卷曲:
jorge@george:~/$ curl -F 'email=jorge@hola.com' -F 'password=12345' http://localhost:3000/api/v1/tokens.json
Response with:
{"token":"azScPXjgppqR1Q3cH82S"}
使用 jQuery
function login() {
$.ajax({
url: "http://localhost:3000/en/api/v1/tokens.json",
type: "POST",
dataType: "json",
data: "email=jorge@hola.com&password=12345",
crossDomain: "true",
beforeSend: function () {
// loading
},
success: function(data) {
// finish load
alert(data.message);
},
error: function(request, type, errorThrown) {
alert(request.status + " " + request.statusText);
}
});
}
使用 jQuery 我收到警报“0 错误”,并且萤火虫显示一个空响应。(32b 大小)。
任何的想法 ?
提前致谢。