0

我想从远程服务器获取一些 json 对象。这是您可以想象的最简单的html:

 <div id="getHotels" data-theme="e" data-role="button">Get hotels</div>
          <ul id="bringHotels" data-role="listview"></ul>

这是javascript:

$("#getHotels").click(function(){

                      $.getJSON("/services/apexrest/Hotels", function(obj){

                                $.each(obj,function(key,value){

                                       $("#bringHotels").append("<li>"+value.Hotel_Name__c+"</li>");


                                       });

                                });
                      });

我从未使用过 getJSON 方法,但它似乎很清楚,尽管它不起作用并且我检查了目录 - 确实有 JSON 数组。所以,如果我做错了,请纠正我,谢谢。

4

1 回答 1

1

There are no enough informations about the problem to solve it...

It could be a problem in the URL you pass to getJSON. Try to change the first slash with a ./, or use other callbacks to obtain more debug infos:

$.getJSON("example.json", function() {
  alert("success");
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
于 2013-11-04T14:55:44.970 回答