0
我想执行一个非常简单的getJson()请求,但无论我更改我从jQuery parseerror。jQuery getJson Parseerror Json数据
我使用ROR 3.01,Mongoid2.0和jQuery 1.5.2
的控制器发送JSON
class SuggestController < ApplicationController
def states
states = States.only(:name, :state_id).where(:country_code => params[:country])
render :json => states.entries
end
end
jQuery来处理响应。
$("#property_country").change(function(){
$.getJSON("/suggest/states",{country: $(this).val(), ajax: 'true'}, function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].state_id + '">' + j[i].name + '</option>';
}
$("select#property_state").html(options);
});
});
$.ajaxSetup({"error":function(XMLHttpRequest,textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
}});
和示例JSON响应
[{"_id":"4d925dbe4aa6936d4f0cdefe","name":"Devon","state_id":1},{"_id":"4d925dbe4aa6936d4f0cdeff","name":"Berwickshire","state_id":2}]
我似乎无法找出为什么即时得到parseerror和它实际上指的。
希望你能指教。
重现此操作没有任何运气:/如果您使用$ .parseJSON在控制台中手动解析响应,是否会出现错误? – 2011-04-02 02:13:56
给出确切的错误 – mkoryak 2011-04-02 02:17:29