JQuery getJSON by php

在php中使用JQ的get json

js code

<script>

$(function() {

var chkDataURL= "API//chkIsSameData.php?name=alonso";

var jqxhr = $.getJSON( chkDataURL, function(jsonresult) {

debugger;

console.log(jsonresult);

})

});

</script>

 

 

/////php code

<?php require_once('連線字串的檔案.php'); ?>


<?php 

  if(isset($_GET['name'])   ){ 
    
 
    $name = $_GET['name']; 

    $sql = "select * from members where name = '".$name ."'";    
        $result = mysqli_query($conn, $sql ) or die(mysqli_error($conn));    
      $rows = mysqli_num_rows($result);
      $response = array(); 
      if($rows > 0){    
        $response =array("Y");
      }
 
    echo json_encode($response); //輸出的格式必須是json
}

?>