2016-10-13 21 views
1

特定の患者情報を選択するためのPHPコードを書いています.pdoを使用してデータベースに接続しました。ファイルの結果はjson形式です。PHPファイルからIntel XDKにjsonデータを取り込む方法

{"success":1,"message":"patient info Available!","patient_info":[{"name":"Nora","gender":"M","email":"[email protected]","Date":"2016-10-17"}]} 

が、私はJSONデータを表示するには、インテルXDKにjsのコードを書いたとき、screen.Howに表示何も出力iはXDKに成功またはメッセージの値を表示することはできません!

<html> 
<body> 

<?php 

require("config.inc.php"); 

$pid = $_GET["id"]; 
$query = " SELECT * FROM patient where PatientID=$pid"; 

try { 
    $stmt = $db->prepare($query); 
    $result = $stmt->execute(); 
} catch (PDOException $e) { 
    $response["success"] = 0; 
    $response["message"] = "Database Error1. Please Try Again!"; 
    die(json_encode($response)); 
} 

$rows = $stmt->fetchAll(); 

if ($rows) { 
    $response["success"] = 1; 
    $response["message"] = "patient info Available!"; 
    $response["patient_info"] = array(); 

    foreach ($rows as $row) { 
     $post = array(); 
     $post["name"] = $row["PName"]; 
     $post["gender"] = $row["Gender"]; 
     $post["email"] = $row["email"]; 
     $post["Date"] = $row["BDate"]; 
     array_push($response["patient_info"], $post); 
    } 

    echo json_encode($response); 
} else { 
    $response["success"] = 0; 
    $response["message"] = "No patient_info Available!"; 
    die(json_encode($response)); 
} 
?> 
</body> 
</html> 

このXDKコード:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
    <script type="text/javascript"> 
     function createXHR() { 
      if (typeof XMLHttpRequest != "undefined") 
       return new XMLHttpRequest(); 
      else 
       return new ActiveXObject("Microsoft.XMLHttp"); 
     } 

     function requestPatientInfo() { 
      var pid = document.getElementById("pid").value; 
      var oXmlHttp = createXHR(); 
      oXmlHttp.open("get", "http://localhost/hospital/GetPatientData2.php?id=" + pid); 
      oXmlHttp.onload = function() { 
       if (oXmlHttp.readyState == 4) { 
        if (oXmlHttp.status == 200 || oXmlHttp.status == 304) { 
         var patients = json.parse(oXmlHttp.responseText); 
         divPatientInfo.innerHTML = patients.message; 
        } 
        else 
         divPatientInfo.innerHTML = oXmlHttp.statusText; 
       }//end if 
      }; //end ready state 
      oXmlHttp.send(null); 
     }//end function requestPatientInfo 
    </script> 
</head> 

<body> 
Enter Patient ID to get All Information 
<p> 
    Patient ID: <input type="number" id="pid"/> 
</p> 
<input type="button" value="Get Info" onClick="requestPatientInfo();"/> 
<div id="divPatientInfo"></div> 
<iframe name="hiddenFrame" style="width:0 ; height:0"></iframe> 

</body> 
</html> 

答えて

0

は、可能なペーストであれば、ここで、放火犯を使用して、チェック、一度AJAX応答を解決しない場合は

var divPatientInfo = document.getElementById('divPatientInfo'); 
    if(oXmlHttp.readyState==4){ 
         if(oXmlHttp.status==200 || oXmlHttp.status== 304){ 
          var patients= json.parse(oXmlHttp.responseText); 
          divPatientInfo.innerHTML=patients.message;   
         } 
         else 
         divPatientInfo.innerHTML=oXmlHttp.statusText; 

        }//end if 

を次のように..あなたがdivPatientInfoを定義していない変更を検索しますもっと助けてください。

+0

まだ動作しません – Malak

+0

は応答がファンクバグに入っていますか?その回答をここに貼り付けることができますか?jqueryベースのコードに一度従ってください。 function requestPatientInfo(var id = $( '#pid')。val(); $アヤックス({ URLます:http://localhost/hospital/GetPatientData2.php、 データ:{ID:ID}、 データ型:JSON、 }、成功:機能(データ){ $( '# divPatientInfo ').html(data.message); }); } jqueryライブラリhttp://code.jquery.com/が含まれていることを確認してください –

関連する問題