怎样才能得到它是由PHP类返回的PhoneGap的价值呢? [英] How can get value in phonegap which is returned by php class?
问题描述
我设计的PhoneGap的与Android项目。我想用警报消息在由我的PHP类返回PhoneGap的显示名称。 这是我的PHP类:
I am designing a project in phonegap with android. i want to show the name using alert message in phonegap which is returned by my php class. This is my php class:
<?php
final class DataStrip
{
public function DataStrip()
{
return "kuntal";
}
}
?>
现在在我的PhoneGap的节目,我想用警报显示此kuntal。请帮我什么将是code做这个功能在PhoneGap的。也请您查看我的PHP类。
Now in my phonegap program i want to display this "kuntal" by using alert. please help me what will be code to do this functionality in phonegap. please check my php class also.
推荐答案
有你的php返回一个JSON对象:
Have your php return a JSON object:
final class DataStrip
{
public function DataStrip()
{
return json_encode(array("result"=>"kuntal"));
}
}
?>
然后在你的PhoneGap应用程序,使用Ajax来获取JSON并提醒它(例如用jQuery进行简洁):
Then in your PhoneGap application, use ajax to get the JSON and alert it (example uses jQuery for brevity):
$.getJSON('http://www.domain.com/mypage.php', function(data) {
alert(data.result);
});
这篇关于怎样才能得到它是由PHP类返回的PhoneGap的价值呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!