我正在做来自 ajax 的渣滓域请求。请求似乎没问题,它成功地访问数据库并返回 200 ok 响应,但在客户端它仍然处于失败块中。这是我的代码。
validate($(".confpassword").val(),$("#psw").val());
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
var email = $("#email").val();
var password = $("#psw").val();
var birthday = $("#birthday").val();
var sendInfo = {
firstname: firstname,
lastname: lastname,
email: email,
password: password,
birthday: birthday
};
$.ajax({
type: 'POST',
url: 'http://localhost:3001/users/create',
data: JSON.sendInfo,
crossDomain: true,
dataType: 'application/json; charset=utf-8',
success: function (data) {
alert('success.............');
},
error: function(){
alert('failure............');
}
});
如果有人知道请帮助我
这是我在 ruby 中的服务器端响应:
def create
@user=User.create(:birthday=> params[:birthday],:email=> params[:email],:firstname=> params[:firstname], :lastname=> params[:lastname],:password=>params[:password])
respond_to do |format|
if @user.save
format.json { render :json => @user,:status=>200}
else
format.json { render :json => @user.errors, :status => :unprocessable_entity}
end
end
end