[PhoneGap] Cross Domain Ajax Calls?

1,436 views
Skip to first unread message

MorningZ

unread,
Apr 23, 2010, 11:37:23 PM4/23/10
to phonegap
Hey everyone...

So I am ramping up for an iPhone app project.... I'm working in
iWebKit right now to generate the HTML and then will pull this into a
PhoneGap XCode project to compile to a native app.... (I'm guessing
iWebKit will play nice with PhoneGap just like jqTouch does)

My question deals with using XUI, since that seems to be the
recommended framework to use with PhoneGap...

In using iWebKit outside of PhoneGap, I'd guess that XUI's XHR methods
won't work calling another domain..... when I pull this into
PhoneGap, does this do any magic fixing of stopping cross domain?

Reason I ask if because Appcelerator actually goes in and removes the
cross domain limitation of JavaScript's base XMLHttpRequest
object.... I was *hoping* I could expect the same "helper" in this
environment....

I'd just try it myself to see if it works, but I am not yet writing
any server side code yet..... I do work in all JSON so I was looking
for something like jsonp-type functionality :-)

If XUI/PhoneGap doesn't "fix" this... whats people's experiences
including jQuery into a PhoneGap project? I'm guessing that jQuery
doesn't play nice with *all* phone OS's, but I'm starting off with
iPhone, then moving to Android... not worried about too much outside
those two right now

Thanks in advance

- Stephen

--
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

Jesse MacFadyen

unread,
Apr 24, 2010, 2:21:05 AM4/24/10
to MorningZ, phonegap
There is no sandbox for accessing data because xhr requests are made
via the file:// protocol so you can easily mashup data/rest Apis.

If you need to access an API that requires you to include a server
side js file you will need to use jsonp.

Sent from my iPhone

Giacomo Balli

unread,
Apr 24, 2010, 3:50:01 AM4/24/10
to phonegap
in addition, there is no cross domain restriction when running a
native app even if developed using PhoneGap (believe cuz an app
doesn't have a domain per se).
Anyways, no need to worry, you can call web content via ajax. works
like a charm!

One question though... why do you use so many frameworks? don't you
find it confusing? From my point of view once you earn the basic
syntax it's very simple to use non of them. Just my POV.

hope the top part helped!

G

On Apr 24, 8:21 am, Jesse MacFadyen <jesse.macfad...@nitobi.com>
wrote:
> There is no sandbox for accessing data because xhr requests are made  
> via the file:// protocol so you can easily mashup data/rest Apis.
>
> If you need to access an API that requires you to include a server  
> side js file you will need to use jsonp.
>
> Sent from my iPhone
>
> For more options, visit this group athttp://groups.google.com/group/phonegap?hl=en?hl=en

MorningZ

unread,
Apr 24, 2010, 9:58:47 AM4/24/10
to phonegap
I'm missing something.... "so many frameworks" meaning what?

HTML for the App using Ajax calls retrieving JSON data from the server
> PhoneGap/XCode to turn it into Native App

am I completely failing to understand your question?

Giacomo Balli

unread,
Apr 24, 2010, 11:33:52 AM4/24/10
to phonegap
Sorry, I guess I misunderstood. Thought you were using iWebKit,
jqTouch and XUI all together... (which still wouldn't be a problem,
just a personal preference).

Good luck with the app!

Cristobal Viedma

unread,
May 25, 2010, 5:51:07 AM5/25/10
to phonegap
Sorry if this seems obvious but...
the "no cross domain restriction when running a native app" is just
for iPhone or any platform?
How should I test this things while developing (looks like if I am not
running a server on my computer the AJAX calls doesn't work at all).

Cristobal Viedma

mobweb

unread,
May 26, 2010, 2:37:45 PM5/26/10
to phonegap
I'm actually facing the exact same problem here. It seems that Android
OS doesn't support XHR nor JSONP. I have not found a way to send &
receive data from my server so far.

I'm trying to port an iPhone application that I made to Android. Said
application relies heavily on pulling data from my server. On the
iPhone this works like a charm, either by using XHR or JSONP (only
tried those 2 so far). On the Android OS however, I just can't make
any contact to the server. Both methods just time out, as if there was
no internet connection.

Is cross domain scripting not supported on Android?

Here is my JSONP code that works just fine on the iPhone, but doesn't
work at all on Android OS:

http://pastebin.com/Mi7TXFep

mark

unread,
May 26, 2010, 4:11:24 PM5/26/10
to phonegap
If we had, er, um TCP SOCKETS we could do cross domain with ease
(and
Bonjour, FTP, etc ).

I think the bounty is up to $200. Anyone, Bueller. . .?
-ml

D. Rimron

unread,
May 27, 2010, 4:22:36 AM5/27/10
to phon...@googlegroups.com
On 26/05/2010 19:37, mobweb wrote:
> I'm actually facing the exact same problem here. It seems that Android
> OS doesn't support XHR nor JSONP. I have not found a way to send&
> receive data from my server so far.
>
Really? It does for me. I have written apps for iPhone and Android, on
IDENTICAL CODE BASES, that use XHR to submit forms, retrieve XML for RSS
readers and JSONP for twitter clients. I'd check your implementation if
I was you, and your package permissions....

> Is cross domain scripting not supported on Android?
>
Your HTML files are still on a file:/// -- so XSS/XDS sandboxing rules
do not apply.

-Dx

Thomas (geomancer)

unread,
May 27, 2010, 11:14:48 AM5/27/10
to phonegap
Hello All,

I just finished testing JSON and AJAX for cross domain issues. It is
true you have to test on the same browser/ server if you are outside
of Android or the Emulator. Either method works within the Android;
see "you are so remote.apk" for AJAX and "JSON Test D.apk" for JSON.
Both are free on Android tools market and don't really do much except
for cross domain issues. I put them there so I could test on my G1
android 1.5 in the real world. If anyone cares about the source code
or how to do this in PhoneGap/ Eclipse, I will be happy to give some
more details.
Regards,
Tom Birchmire

Avinash

unread,
May 27, 2010, 11:26:50 AM5/27/10
to Thomas (geomancer), phonegap
Hello Tom,

I have downloaded and tested both the apps on my Android device and both are working fine.
Would you be kind enough to share the code please.

Thank you very much,
Avinash

azayed

unread,
May 27, 2010, 12:18:33 PM5/27/10
to phonegap
Hello Guys!

I have the same problem but with symbian! I can´t do XHR call using
xml document. I don´t recieve any response from the server as if I havn
´t internet connection. I don´t know if it´s emulator problem or
what... did anybody try to use xhr calls using symbian?

On 27 mayo, 17:26, Avinash <kazaavin...@gmail.com> wrote:
> Hello Tom,
>
> I have downloaded and tested both the apps on my Android device and both are
> working fine.
> Would you be kind enough to share the code please.
>
> Thank you very much,
> Avinash
>

> > phonegap+u...@googlegroups.com<phonegap%2Bunsubscribe@googlegroups.c om>

mobweb

unread,
May 27, 2010, 1:02:41 PM5/27/10
to phonegap
Hey,

Thanks for the heads-up. You pointed me in the right direction, now I
got JSONP to work, I guess XHR would work, too. What I had to do is
add the permission flag "INTERNET" to AndroidManifest.xml, see:
http://developer.android.com/reference/android/Manifest.permission.html#INTERNET

:)

Avinash

unread,
May 27, 2010, 1:25:48 PM5/27/10
to mobweb, phonegap
Wow!

That was simple, thanks MobWeb my code also is working on Android device.
Thank you all of you who have taken the time in posting and helping us.

Avinash

Thomas Birchmire

unread,
May 27, 2010, 3:04:09 PM5/27/10
to Avinash, Thomas (geomancer), phonegap
Hi Avinash,

Here's a link to the source code you can download and unzip. 
http://geo781.com/sourcecode/

Remember this is for Phonegap/Android using Eclipse.  

Regards,  Tom Birchmire

Internet Content Developer
tbirc...@usa.net




------ Original Message ------
Received: Thu, 27 May 2010 11:27:25 AM EDT
From: Avinash <kazaa...@gmail.com>
To: "Thomas (geomancer)" <tbirc...@usa.net>
Cc: phonegap <phon...@googlegroups.com>
Subject: Re: [PhoneGap] Re: Cross Domain Ajax Calls?


Hello Tom,

I have downloaded and tested both the apps on my Android device and both are working fine.
Would you be kind enough to share the code please.

Thank you very much,
Avinash

On Thu, May 27, 2010 at 11:14 AM, Thomas (geomancer) <tbirc...@usa.net> wrote:
Hello All,

I just finished testing JSON and AJAX for cross domain issues.  It is
true you have to test on the same browser/ server if you are outside
of Android or the Emulator.  Either method works within the Android;
see "you are so remote.apk" for AJAX and "JSON Test D.apk" for JSON.
Both are free on Android tools market and don't really do much except
for cross domain issues.   I put them there so I could test on my G1
android 1.5 in the real world.  If anyone cares about the source code
or how to do this in PhoneGap/ Eclipse, I will be happy to give some
more details.
Regards,
Tom Birchmire

Avinash

unread,
May 27, 2010, 3:11:54 PM5/27/10
to Thomas Birchmire, phonegap
Thank you Tom,

Avinash
Reply all
Reply to author
Forward
0 new messages