0

I want to get some json object from a remote server. Here is the simplest html you can imagine:

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

and here is the javascript:

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

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

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

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


                                       });

                                });
                      });

i have never used the getJSON method but it seems to be quite clear, despite that it doesnt work and I checked the directory - there really is JSON array. So, if I am doing it wrong, please correct me, thank you.

codeman
  • 47
  • 1
  • 3
  • 9
  • Did you tried a bit of debug? Try to console.log the returning object and check the result... – ProGM Nov 04 '13 at 14:21
  • @ProGM, yes your point is right, but I do it in xcode and it's iOS-cordova application, and all i have is the iOS simulator without any debug windows. aargh – codeman Nov 04 '13 at 14:46
  • 1
    creating app without debugging is something terrible. Check some tutorial: http://stackoverflow.com/questions/4022152/how-to-see-the-javascript-errors-of-phonegap-app-in-xcode http://stackoverflow.com/questions/9693449/no-device-ready-and-no-console-log-with-xcode-using-cordova-1-5 https://github.com/phonegap/phonegap/wiki/Debugging-in-PhoneGap – ProGM Nov 04 '13 at 16:42

1 Answers1

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"); });
ProGM
  • 6,949
  • 4
  • 33
  • 52