jquery - Why is responseText returning blank? -
i have database table fields contain latitude , longitude coordinates of positions. want create markers google map view using information database.
i've implmented query function
function getcords(){ $link = connectdb(); $query = "select * tour"; $results = mysqli_query($link, $query); $jsonarray = array(); while ($row = mysqli_fetch_assoc($results)){ $jsonarray[] = array('filename' => $row['filename'], 'lat' => $row['lat'], 'lon' => $row['lon']); } return json_encode($jsonarray); } when call function php page, returns usual json format.
my issue executing ajax query. have query function above in php scripts file containing 6 or utility functions controlling login, logout, registration , like. query database via jquery, tried
var request = $.ajax({ type:"get", url: "includes/phpscripts.php?action=cords", type: "json" }); var response = request.responsetext; my problem response empty. due formation of url or other reason?
$.ajax({ type:"get", url: "includes/phpscripts.php?action=cords", datatype: 'json', // necessary, because you're sending json server success: function(response) { // response catch within success function console.log(response); } }); or
var request = $.ajax({ type:"get", url: "includes/phpscripts.php?action=cords", datatype: 'json', // necessary, because you're sending json server }).done(function(response) { console.log(response); }); note
instead of return json_encode($jsonarray);, use echo json_encode($jsonarray);
Comments
Post a Comment