Reputation: 1391
I'm running the iPhone 5.0 Simulator within Xcode 4.3. PhoneGap 1.4.1 is installed. I have the following index.html file, similar to the example at http://wiki.phonegap.com/w/page/42450600/PhoneGap%20Ajax%20Sample:
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Ajax Sample</title>
<script type="text/javascript" src="phonegap-1.4.1.js"></script>
<script>
function appReady(){
var ajax = new XMLHttpRequest();
ajax.open("GET","http://search.twitter.com/search.json?q=bacon",true);
ajax.onreadystatechange=function(){
alert(ajax.readyState);
alert(ajax.status);
if(ajax.readyState==4 && (ajax.status==200)){
document.getElementById('main').innerHTML = ajax.responseText;
}
}
ajax.send();
}
document.addEventListener("deviceready", appReady, false);
</script>
</head>
<body onload="onBodyLoad()">
<div id="main">
<p>before load</p>
</div
</body>
</html>
With the debugging alert() calls in place, I see dialogs showing 2, then 401, then 3, then 401, then 4, then 401.
The 401 dialogs indicate, of course, that the request is unauthorized. I've tried websites other than twitter with no success. I am able to use Safari on the simulator to browse the web. The code above runs as expected on my Droid 2 when I create a PhoneGap Android project in Eclipse on Windows. I'm new to iOS and PhoneGap development, so I may be overlooking something simple. Any ideas?
BTW, there are one or two other questions on SO about this, but the setups are different, such as one used OAuth.
Upvotes: 1
Views: 1970
Reputation: 1391
I just needed to add search.twitter.com to PhoneGap.plist/ExternalHosts.
Upvotes: 2