details.js
$(document).ready(function()
{
$.ajax({
url: 'js/index.php',
dataType: 'jsonp',
jsonp: 'callback',
timeout: 5000,
success: function(data){
$.each(data, function(key,val){
console.log(val.NAME);
});
},
error: function(){
alert('There was an error loading the data.');
}
});
});
index.php
<?php
if($_SERVER['REQUEST_METHOD']=="GET")
{
$callback= $_GET['callback'] ;
$db=mysqli_connect("localhost","username","password","detail")or die (" error connection");
$d = mysqli_query($db, "select * from data") or die ("Query error");
while($m = mysqli_fetch_assoc($d))
$output[]=$m;
mysqli_close($db);
$data= json_encode($output);
echo $callback.'('.$data.')';
?>
I am creating a cordova application in which i need to get the data from a php file index.php ,details are taken from database mysql.The connection with mysql and inserting values etc is perfectly done and these details are encoded to json format:-
[{"ID":"1","NAME":"abc"}]-this output of php file is displayed properly
Now i need to get these values in a javascript file.I have tried the above code,but in the console 'NAME' for example is not displayed or I couldn't get the details.How can i solve this.
Can anybody please help me in this.