简体   繁体   中英

Using phonegap, is there a way for an Android device to communicate with PHP?

I have a php page which connects an API and gets information back which can then be displayed.

I'd like to turn this into an app for Android. I've heard of PhoneGap, which I know uses javascript, html, and css. I know javascript is capable of calling php files, but I am unsure how or if its even possible to call a php file from an android device. I'm not sure if android browsers can handle php, or what the deal is with them. So if you have any information on that, I'd appreciate it.

I'm also willing to rewrite the API call in javascript, but I don't think thats possible. If you think differently, please let me know what you're talking about.

Android cannot talk directly to PHP. What phonegap, javascript, etc.. are doing is simply issuing HTTP requests that happen to be handled by a PHP script.

The PHP code will execute, output some data (json, html, xml, gif, jpg, etc...) and send that out as a the HTTP request's reply.

PHP is just a server side language so it doesn't matter if your browser "can or cannot" handle it, only HTML is returned (unless you set a different content-type).

You may be worth while looking into REST style JSON api's which would allow a XMLRequest to be sent to. Have a look at this document

Theres also a nice tutorial here which shows how to call a REST API and a PHP Tutorial here to create a REST API.

1.It dosent matter to PhoneGap where the PHP is hosted or Its PHP OR ASP.NET OR ASP.NET MVC
2.If You wanna host your PHP code yourself in production (You mayb shouldn't do this in production). then you need a server and a static IP address
3.if you just wanna setup a PHP server for developmental purposes then just tie it to 127.0.0.1:81 and you can directly use this address it doesn't matter whether you have a static IP address or not.

我已经使用jsonp http://en.wikipedia.org/wiki/JSONP通过phonegap做到了这一点

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM