dongzhong1929
2014-12-30 13:56
浏览 46
已采纳

如何使用phonegap中的json从php获取数据

How to fetch the data from the php using json in phonegap, On server xampp, I just write the following code replay.php. I have taken these example from this line and and I want to mention this question from stackover flow, try to make according to it but my android emulator is not resounding, please help me on this topic, I am new in phonegap and android,

replay.php

<?php
header('Content-Type: application/json');
$choice =$_POST["button"];
$cars = array("Honde", "BMW" , "Ferrari");
$bikes = array("Ducaite", "Royal Enfield", "Harley Davidson");
if($choice == "cars") print json_encode($cars);
    else 
print json_encode($bikes);
?>

In eclipse I write the following code in index.html

<!DOCTYPE html>
<html>
<head>
    <script charset="utf&minus;8" type="text/javascript">
    function connect(e)
    {
        var term= {button:e};
        $.ajax({
        url:'http://localhost/Experiements/webservices/reply.php',
        type:'POST',
        data:term,
        dataType:'json',
        error:function(jqXHR,text_status,strError){
        alert("no connection");},
        timeout:60000,
        success:function(data){
            $("#result").html("");
                for(var i in data){
                    $("#result").append("<li>"+data[i]+"</li>");
                }
            }
        });
    }
    </script>
</head>
<body>
    <center><b>Bikes or Cars</b></center>
    <center><input onclick="connect(this.value)" type="button" value="cars" /></center>
    <center><input onclick="connect(this.value)" type="button" value="bikes" /></center>
    <center><b>Results</b></center>
    <ul id="result"></ul>
</body>
</html>

图片转代码服务由CSDN问答提供 功能建议

如何使用phonegap中的json从 php获取数据</ strong>, 服务器xampp ,我只需编写以下代码 replay.php </ strong>。 我从这一行</ a >和我想提及来自堆栈流程的这个问题 ,尝试根据它制作,但我的机器人模拟器没有响亮,请帮助我这个主题,我是新的 phonegap和android,</ p>

重播 .php </ strong> </ p>

 &lt;?php 
header('Content-Type:application / json'); 
 $ choice = $ _ POST [“button”]  ; 
 $ cars = array(“Honde”,“BMW”,“Ferrari”); 
 $ bikes = array(“Ducaite”,“Royal Enfield”,“Harley Davidson”); 
if($ choice ==  “cars”)打印json_encode($ cars); 
 else 
print json_encode($ bikes); 
?&gt; 
 </ code> </ pre> 
 
 

在eclipse中我写下面的内容 代码 index.html </ strong> </ p>

 &lt;!DOCTYPE html&gt; 
&lt; html&gt; 
&lt; head&gt; 
&lt; script  charset =“utf&amp; minus; 8”type =“text / javascript”&gt; 
 function connect(e)
 {
 var term = {button:e}; 
 $ .ajax({
 url:  'http://localhost/Experiements/webservices/reply.php',
类型:'POST',
 data:term,
 dataType:'json',
 error:function(jqXHR,text_status,strError)  {
 alert(“no connection”);},
 timeout:60000,
 success:function(data){
 $(“#result”)。html(“”); 
 for(var i 在数据中){
 $(“#result”)。append(“&lt; li&gt;”+ data [i] +“&lt; / li&gt;”); 
} 
} 
}); 
  } 
&lt; / script&gt; 
&lt; / head&gt; 
&lt; body&gt; 
&lt; center&gt;&lt; b&gt;自行车或汽车&lt; / b&gt;&lt; / center&gt; 
&lt; center&gt;&lt;输入 onclick =“connect(this.value)”type =“button”value =“cars”/&gt;&lt; / center&gt; 
&lt; center&gt;&lt; input onclick =“connect(this.value)”type =“ 按钮“value =”bikes“/&gt;&lt; / center&gt; 
&lt; center&gt;&lt; b&gt;结果&lt; / b&gt;&l  t; / center&gt; 
&lt; ul id =“result”&gt;&lt; / ul&gt; 
&lt; / body&gt; 
&lt; / html&gt; 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题