AJAX to a port other than 80?

1,379 views
Skip to first unread message

Alex Sudakar

unread,
May 28, 2014, 8:04:59 AM5/28/14
to phon...@googlegroups.com
Hi.  This is a very basic question; I'm new to both Cordova and the world of Apps.  (Thank goodness something like this exists; I'd go crazy if I had to learn specific languages and platforms for every separate type of device!  Many thanks to the developers.)

I've written a trivial test App which does a simple AJAX call to my test web server, which is listening on both port 80 and 6666.

When my App uses a URL without specifying any specific port it works fine; it sends the request to the web server on port 80, it replies, the $.ajax call (I'm using jQuery) returns with the test data.

When I specify a non-standard port, using the URL 'http://192.168.0.2:6666/ajax.php', the AJAX call returns an error.

I've searched this group and also the web, and I can see lots of information on how to set things so CORS is enabled.  My config.xml has the '<access origin="*" />' directive set, and this is clearly working, I think, since my App can happily access the web server on the standard port 80.  I haven't found anything that addresses non-standard ports.

I've run my App in a couple of Android emulators and a physical iPhone 4.  The native web browsers on those devices also can't access my web server on the non-standard port - one returns a 'webpage not available', the other a 'net::ERR_UNSAFE_PORT' error popup.

So it looks to me that mobile devices are simply set to only allow web browsing / AJAX to the standard port.  I wanted to confirm that this is the case; I'm a bit surprised.  I come from a standard web development sphere where my web pages can be served from a non-standard port and the AJAX calls just work automatically to that same port.

Can folks here confirm what limits AJAX has to non-standard ports in Cordova?  Must any web server I access from my App be accessible only on port 80?  Or point me at some reference material that can teach me a bit more about this?

Thanks!

Zoltán Birner

unread,
May 29, 2014, 5:05:08 AM5/29/14
to phon...@googlegroups.com
Hi Alex,

I can confirm you can  use different listening port, I was build  an application which  communicate with a  webserver, and user can change the port.

You should check the  configuration  on server-side. (http://enable-cors.org/server_php.html)

Greg Allensworth

unread,
May 29, 2014, 10:48:48 AM5/29/14
to phon...@googlegroups.com
Using a non-80 port should work just fine.

But I would point out a consideration: Some wifi hotspots don't allow
traffic to ports other than 80. If someone tries to use your app
(accessing your service on port 6666) on borrowed wifi, the connection
may not work due to the hotspot blocking it. For that reason I would
stick to the most common ports possible: 80, 8000, and 8080.

-g
> --
> -- 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
> ---
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to phonegap+u...@googlegroups.com
> <mailto:phonegap+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
Greg Allensworth, Senior Web GIS Developer
BS A+ Network+ Security+ Linux+ Server+

GreenInfo Network - Information and Mapping in the Public Interest
564 Market Street, Suite 510 San Francisco CA 94104
PH: 541-223-7636 email: gre...@greeninfo.org
Web: www.GreenInfo.org www.MapsPortal.org

Subscribe to MapLines, our e-newsletter, at www.GreenInfo.org
Reply all
Reply to author
Forward
0 new messages