I am trying to fetch date format in the form of json object from database. The code is like
$.ajax({
url: 'index.php?action=getDateFormat',
type: 'POST',
dataType: 'JSON',
success: function(data){
if (data.length)
{
var jsonData = JSON.parse(data);
return jsonData["DateFormat"];
}
}
});
Note that in console of browser, the data is "Object { dateFormat: "d-m-Y" }".
The above code is returning "undefined". Please help !!!
in php code
$dateFormatArray = array("dateFormat" => $dateFormat);
json_encode( $dateFormatArray);
In console of browser the result of data is
Object { dateFormat: "d-m-Y" }
Full code
function getDateFormat()
{
var dateFormat ="";
$.ajax({
url: 'index.php?action=getDateFormat',
type: 'POST',
dataType: 'JSON',
success: function(data)
{
dateFormat = data.dateFormat;
}
});
return dateFormat;
}