dongmou3615 2016-05-30 05:41
浏览 83

无法使用cordova上的ajax从服务器检索数据json

I tried to call / search data by ID , from the server using ajax in cordova , but when I click to display the data " undefined" , what's wrong ???

This my html

<input type="text" id="result"  value=""/>
<a href="javascript:get()" style="text-decoration: none"><button>get</button></a>
<div id="result2"></div>

            function get (){    
                var qrcode = document.getElementById ("result").value;
                var dataString="qrcode="+qrcode;
                $.ajax({
                    type: "GET",
                    url: "http://localhost/book/find.php",
                    crossDomain: true,
                    cache: false,
                    data: dataString,
                    success: function(result){
                    var result=$.parseJSON(result);
                    $.each(result, function(i, element){        
                        var id_code=element.id_code;
                        var qrcode=element.qrcode;
                        var judul=element.judul;
                        var hasil2 = 
                            "QR Code: " + qrcode + "<br>" +                 
                            "Judul: " + Judul;  

                        document.getElementById("result2").innerHTML = hasil2;  
                    }); 
                    }
                });
            }

This my script on server

include "db.php";

    $qrcode= $_GET['qrcode'];
    $array = array();

    $result=mysql_query("select * from book WHERE qrcode LIKE '%{$qrcode}%'");

    while ($row = mysql_fetch_array($result)) {  //fetch the result from query into an array
    {
        $array[] =$row['qrcode'];
        $array[] =$row['judul'];
        $array[] =$row['jilid'];

    }
    echo json_encode($array);  
    } 
  • 写回答

3条回答 默认 最新

  • doujianjian2060 2016-05-30 06:17
    关注

    try to change your parameter in calling ajax

    var dataString = {qrcode : qrcode };

    评论

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条