在我的控制器中我有:
def rate
@konkurrencer = Rating.where(:IP => @ip, :konkurrencer_id => params[:id])
if @konkurrencer.empty?
render :nothing => true
else
render :status => 500, :text => "This server hosted at sadasa"
end
end
end
我的ajax电话:
jQuery.ajax({
url: frm.attr('action'), //your server side script
data: frm.serialize(), //our data
type: 'POST',
success: function (data) {
$('.warning').fadeIn(500).css({display: 'block',
position: 'absolute',
left: position.left + 50,
top: position.top - 25
}).html('Du har stemt').fadeOut(1000),
$(ri).next('.ratingcount').html('asdasdasd')
},
error: function (msg) {
alert(msg); //something went wrong.
}
});
问题是警告中显示的消息是[object Object]
而不是文字This server hosted at sadasa
答案 0 :(得分:3)
这可能主要是因为jQuery ajax的错误函数可能有3个参数:error(jqXHR, textStatus, errorThrown)
。第一个是XMLHttpRequest对象。查看更多:http://api.jquery.com/jQuery.ajax/
<强>解决方案强> 尝试将您的错误功能替换为:
error: function (responseObject) {
alert(responseObject.responseText); //something went wrong.
}
希望有所帮助!
答案 1 :(得分:2)
将alert(msg)
更改为alert(msg.responseText)