1

I'm developing an iPhone web app with dashcode. My app runs fine when I browse it with the iphone simulator. When I deploy it to a web-server, I never get a response from XMLHttpRequests. Here's the code I use:

function get(feedURL, handler) {
    var onloadHandler = function() { handler(xmlRequest); };    
    var xmlRequest = new XMLHttpRequest();
    xmlRequest.onload = onloadHandler;
    xmlRequest.open("GET", feedURL);
    var credentials = encodeBase64(_login.username + ':' + _login.password);
    xmlRequest.setRequestHeader("Authorization", "Basic " + credentials);
    xmlRequest.send();
}

When I attach a onreadystatechange handler, I can see the the request goes to state 4. I can also see the requests in my server logs. I also added a "no cache" request header, which didn't help. I tried this on a local web-server on a hosting package that I have and I don't have any luck getting it to work.

dlinsin
  • 19,249
  • 13
  • 42
  • 53
  • So `responseText` is an empty string when `readyState` reaches `4`? – kangax Aug 25 '09 at 22:36
  • 1
    Are you alphanumeric username and password? I've noticed using the standard SDKs that the iPhone is a bit flaky with Basic Auth. Have you tried using a http://user:password@host/path URL instead of manually setting the header? The XML request probably isn't planning to handle the Basic Auth headers it receives in response and is returning nothing. Depending on username and password, you will need to percent encode them to stick them into the URL. – Douglas Mayle Sep 16 '09 at 07:21
  • when readyState reaches 4, what are the values of status and statusText? also try getAllResponseHeaders() for more info – slf Sep 18 '09 at 19:40

3 Answers3

2

A shot in the dark, but the apple docs say this.

the domain of the URL request destination must be the same as the one that serves up the page containing the script. This means, unfortunately, that client-side scripts cannot fetch web service data from other sources, and blend that data into a page. Everything must come from the same domain. Under these circumstances, you don't have to worry about security alerts frightening your users.

What are the values of status and statusText? Also try getAllResponseHeaders() for more info.

Also, if it's just basic auth you want, you can just pass it to open() like so:

open("method", "URL", asyncFlag, "userName", "password")
slf
  • 22,595
  • 11
  • 77
  • 101
1

The iPhone probably isn't expecting to receive Basic Auth headers, since you manually set the request header. Try adding the username and password to the URL (after percent encoding) and run the request that way.

Douglas Mayle
  • 21,063
  • 9
  • 42
  • 57
0

Maybe try the new debugging capabilities that are part of DashCode 3.0 (new with Snow Leopard)? Not really an answer, but perhaps a change of scenery -- or the new debugger -- will shake something loose.

slothbear
  • 2,016
  • 3
  • 21
  • 38