0
我想渲染一个局部调用一个ajax函数并将它呈现在div中。用ajax和json响应部分渲染
在下面的代码中,request.responseText
给了我我想要的html,但为什么这个响应会进入错误函数并且不成功? 看起来很简单,但我在这里错过了一些东西。 员额响应状态代码是 “200 OK” 在铬的检测元件
JS代码:
$.ajax({
url: "/upload/get_detail.json",
type: "POST",
dataType: "json",
data: { id: id },
success: function(result) {
$('.some-label').html(result);
},
error: function (request, status, error) {
alert(request.responseText);
}
}).done(function() {
//some code
});
控制器:
def get_detail
@logs = Detail.where('category_id = ?', params[:id].to_i).limit(20)
render :partial => "/category/detail", :layout=> false
end
responseText的外观如何? – cfs 2013-05-07 17:33:03
很可能你的*“html”*不是json。 – 2013-05-07 17:33:51
这是一个HTML。其实很好的问题,因为我忘了包括重要的部分,错误:'Unexpected token <' – tostasqb 2013-05-07 17:34:57