[PhoneGap] XMLHttpRequest.status returns 0 on Android device, works fine on iPhone

3,291 views
Skip to first unread message

mobweb

unread,
May 24, 2010, 2:21:18 PM5/24/10
to phonegap
Hey,

I am developing an application for iPhone OS and Android. I use an
XMLHttpRequest to send a string to my server.
On the iPhone OS, it works fine. On Android however, the
XMLHttpRequest.readyState switches to 4, but the XMLHttpRequest.status
always returns 0, not 200, as it does on the iPhone.

Are there any restrictions that I need to work around? Like I said the
file is on a remote server.

Here's the relevant code: http://pastebin.com/5ryZtQyi

Thanks for any help! :)

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Avinash

unread,
May 24, 2010, 3:46:04 PM5/24/10
to mobweb, phonegap
As far as I understand, Android browser does not allow cross-domain XMLHttpRequest calls even if the JS is loaded by  a file:// protocol while iPhone browser allows such calls.

Work around is using JQuery JSONP

Thanks,
Avinash

mobweb

unread,
May 24, 2010, 4:00:19 PM5/24/10
to phonegap
Thank you. Do you know if there's a workaround that doesn't require
any extra libraries? Because implementing jQuery into my application
just for this function seems a bit overkill...

On 24 Mai, 21:46, Avinash <kazaavin...@gmail.com> wrote:
> As far as I understand, Android browser does not allow cross-domain
> XMLHttpRequest calls even if the JS is loaded by  a file:// protocol while
> iPhone browser allows such calls.
>
> Work around is using JQuery JSONPhttp://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getJSON_....
>
> Thanks,
> Avinash
>
>
>
> On Mon, May 24, 2010 at 2:21 PM, mobweb <i...@mobweb.ch> wrote:
> > Hey,
>
> > I am developing an application for iPhone OS and Android. I use an
> > XMLHttpRequest to send a string to my server.
> > On the iPhone OS, it works fine. On Android however, the
> > XMLHttpRequest.readyState switches to 4, but the XMLHttpRequest.status
> > always returns 0, not 200, as it does on the iPhone.
>
> > Are there any restrictions that I need to work around? Like I said the
> > file is on a remote server.
>
> > Here's the relevant code:http://pastebin.com/5ryZtQyi
>
> > Thanks for any help! :)
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "phonegap" group.
> > To post to this group, send email to phon...@googlegroups.com
> > To unsubscribe from this group, send email to
> > phonegap+u...@googlegroups.com<phonegap%2Bunsu...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > For more info on PhoneGap or to download the code go towww.phonegap.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/phonegap?hl=en?hl=en

Andrew Lunny

unread,
May 24, 2010, 4:02:32 PM5/24/10
to mobweb, phonegap
0, not being a valid HTTP status code, is used by browsers to indicate
success for a non-http xhr response (for example, using the file://
protocol)

see the following:
https://developer.mozilla.org/En/Using_XMLHttpRequest#Example.3a.c2.a0Non-HTTP_synchronous_request

I would recommend checking the request's responseText attribute if the
status is set is 0 - the request may still be completing as intended.
--
Andrew Lunny
Software Developer, Nitobi
604 685 9287
blogs.nitobi.com/andrew

mobweb

unread,
May 26, 2010, 2:40:32 PM5/26/10
to phonegap
@Avinash: JSONP doesn't seem to work either:
http://groups.google.com/group/phonegap/browse_thread/thread/829884c7fe517f56
@Andrew Lunny: Thanks for the suggestion, but the responseText is
empty. I actually checked on my server to see if the application on my
Android device ever managed to send some data there, but it seems that
no contact has been made. :/

I answered to another thread, because it seems to deal with the same
problem: http://groups.google.com/group/phonegap/browse_thread/thread/829884c7fe517f56

On 24 Mai, 22:02, Andrew Lunny <andrew.lu...@nitobi.com> wrote:
> 0, not being a valid HTTP status code, is used by browsers to indicate
> success for a non-http xhr response (for example, using the file://
> protocol)
>

> see the following:https://developer.mozilla.org/En/Using_XMLHttpRequest#Example.3a.c2.a...

> For more options, visit this group athttp://groups.google.com/group/phonegap?hl=en?hl=en

Reply all
Reply to author
Forward
0 new messages