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 };

    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析