I want to convert values that get from ajax into an array, from which I can get values and format them.
$(document).ready(function() {
$('#documenter_nav > li a').click(function(){
var url = $(this).attr('data-url');
$.getJSON(url, function(data){
var html = "";
var vlerat = "";
var myData = data.content;
$.each(myData, function(index){
$.each(myData[index], function(key, value){
vlerat += key;
html += value;
});
});
$("#documenter_content").html(vlerat);
});
return false;
});
});
From what I have done it gives me all keys and values from database as string. I want to get an array, and display diferent vales of array in different tags of html.
In your ajax file, store your values into a JSON object.
$array = array(
'value1'=>$value1,
'value2'=>$value2
);
echo json_encode($array);
and then in your jQuery, you can extract them using something like this...
var request = $.ajax({
url:'ajax url here',
type:'POST',
dataType:'json',
});
request.done(function(Response){
alert(Response.value1);
});