简体   繁体   English

使用phonegap,Android设备是否可以与PHP通信?

[英]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. 我有一个连接API的php页面,并获取可以显示的信息。

I'd like to turn this into an app for Android. 我想将其变成适用于Android的应用。 I've heard of PhoneGap, which I know uses javascript, html, and css. 我听说过PhoneGap,我知道它使用javascript,html和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. 我知道javascript能够调用php文件,但是我不确定如何或是否有可能从android设备调用php文件。 I'm not sure if android browsers can handle php, or what the deal is with them. 我不确定android浏览器是否可以处理php,或者与它们有何关系。 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. 我也愿意用javascript重写API调用,但是我认为那是不可能的。 If you think differently, please let me know what you're talking about. 如果您有不同的想法,请告诉我您的意思。

Android cannot talk directly to PHP. Android无法直接与PHP对话。 What phonegap, javascript, etc.. are doing is simply issuing HTTP requests that happen to be handled by a PHP script. phonegap,javascript等的作用是简单地发出恰好由PHP脚本处理的HTTP请求。

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代码将执行,输出一些数据(json,html,xml,gif,jpg等),并将其作为HTTP请求的答复发送出去。

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). PHP只是一种服务器端语言,因此浏览器“可以或不能”处理它并不重要,仅返回HTML (除非您设置其他内容类型)。

You may be worth while looking into REST style JSON api's which would allow a XMLRequest to be sent to. 您可能值得考虑一下REST风格的JSON api,它可以将XMLRequest发送到。 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. 这里还有一个不错的教程 ,它展示了如何调用REST API,这里的PHP教程创建了REST API。

1.It dosent matter to PhoneGap where the PHP is hosted or Its PHP OR ASP.NET OR ASP.NET MVC 1,与托管PHP的PhoneGap或其PHP或ASP.NET或ASP.NET MVC息息相关
2.If You wanna host your PHP code yourself in production (You mayb shouldn't do this in production). 2.如果您想在生产中自己托管PHP代码(您可能不应该在生产中这样做)。 then you need a server and a static IP address 那么您需要一个服务器和一个静态IP地址
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. 3.如果您只是想为开发目的设置PHP服务器,则只需将其绑定到127.0.0.1:81即可直接使用此地址,无论您是否具有静态IP地址都没有关系。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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