在document ready中调用getJSON静默失败
call to getJSON in document ready failing silently
我在文档中准备了两次调用getJSON,都是为了在页面上填充不同的组合框。第一个工作没有问题。第二个不填充控件,但我可以从我的日志中看到,它已经从模型请求数据,控制器也获得数据。
$.getJSON(
'<%= pathtomethod%>',
function(data) {
data = $.parseJSON(data); //converting to a javascript object vs. just string....
// console.log(data);
if (data !=null){
$.each(data, function(i) {
$('#ruletypes')
.append($("<option></option>")
.attr("value",this.id)
.text(this.name));
}); //end .each
}//end if
}//end function(data)
);//end getJSON.
//populate rule conditions drop down box.
$.getJSON(
'<%= pathtomethod%>',
function(data) {
data = $.parseJSON(data); //converting to a javascript object vs. just string....
console.log(data);
if (data != null) {
$.each(data, function(i) {
$('#rule_condition')
.append($("<option></option>")
.attr("value",this.id)
.text(this.description));
}); //end .each
}//end if
}//end function(data)
);//end getJSON.
控制台中没有出现错误。但也没有数据出现……下面是rule_condition下拉列表的html:
<div class="first">
<select id='rule_condition' name='rule_condition'>
</select>
</div>
编辑1
我找到了罪魁祸首。在第二个请求中返回的数据包含单引号。现在我只是在谷歌上查找如何处理json数据中的嵌入引号您应该尝试实现成功和错误函数,并观察错误是什么。另外,尝试使用firebug
相关文章:
- 如何将getJson的响应保存在全局变量中
- 使用本地文件而不是$.getJSON
- jQuery.getJSON失败,语法错误
- 带有Spring的$.getJSON未执行回调
- jQuery$.getJSON抛出意外令牌
- ASP.Net AJAX$GetJson函数获胜'不要被处决
- Ember.js:将Em.$.getJSON转换为promise并将响应绑定到控制器上下文的正确方法
- 为什么有些jQuery程序员使用像$.get、$.getJSON和$.when这样的jQuery函数来代替$.ajax
- 在ruby on rails中使用jquery getJSON获取数据
- $.每个jquery循环打印一个“;未定义的“;对于getJSON请求后的每个元素,网格数据都会完美地打印出来
- 如何使用pass参数从jQuery.getJSON获取回调
- 可以't通过$getJSON上传参数使用js.coffee
- 使用$.getJSON循环遍历数组
- 在Flask中使用.getJSON请求时,只运行一次命令
- Jquery将循环变量绑定到getJSON函数
- 试图封装$.getJSON和RequireJS
- 当站点不是其URL的根时,如何在getJSON调用中定位API
- 在jquery中等待getJSON完成的回调
- 在document ready中调用getJSON静默失败
- 美元.getJSON在检索数据时获得静默错误