Question

I'm currently working on a mobile app at the moment. Using PhoneGap 1.1.0 on an iOS 5 iPhone 4.

I have some of the basics working. I haven't been working on it long and now I need to be able to get some JSON data from an external server on the web.

I am using the javascript framework XUI rather than the jQuery because of the file size. XUI is a good little JavaScript framework but lacks documentation.

I want to grab the data using a XHR request. But for some reason I am now unable to access the data (I previously have had the request working but been off the project for a while and don't know whats happening so looking for someone to help) and I don't know why.

The request is below (just requesting data from the twitter api currently):

x$( '#button' ).touchstart(function(e) {
           x$('#test').xhr('https://twitter.com/status/user_timeline/MY_TWITTERNAME.json?count=10&callback=?t', {
                    async: true,
                    method: 'post',
                    callback: function() {
                        alert("The response is " + this.responseText);
                    }
            });
});

The DIV '#test' is just a blank DIV but I'm not sure if a DIV needs to be declared within this selector.

I have also set the external hosts in the PhoneGap.plist to include the domain 'www.twitter.com'.

Any help would greatly be appreciated as I can't see where Im going wrong.

Was it helpful?

Solution

Got it working. Slight problem in my PhoneGap.plist file.

My file code I used to call the server was:

x$( '#button' ).touchstart(function(e) {
                x$().xhr('http://www.url.co.uk/Mobile/test.php', 
                    function(){
                        alert(this.responseText);
                    }
                );
});

Had to make sure that url was in full and correct, including 'http://'.

I then went and made sure my PhoneGap.plist was correct. I tried a few different changes and then found the fault was by having a slash on the end of the url ('www.myurl.com/').

If your using PhoneGap 1.1.0 you need to name the external domains you will be accessing within the PhoneGap.plist. These are to be named in the section 'External Hosts' and when specifying your hosts domain it must just be in the following format 'www.domainname.com' and not include 'http://'.

I hope this helps anyone else.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top