Once upon a time, I was using PHP to display all my data. Now I want to use AJAX.
Where I used to get my data in PHP:
<?php
$array = $this->disparray;
foreach($array as $key => $value){
$mlsnum = $value['1'];
echo "<div>" . $mlsnum . "</div>";
}
?>
Where $this->disparry was some function in joomla that put data into an array. The structure of which looked like
array (
0 => array (
0 => data1,
1 => data2,
);,
1 => array (
0 => data1,
1 => data2,
);,
);
now I have an AJAX function that works (or at least returns an alert.
var results = $('#hidden').serialize();
var url = 'index.php?option=com_mls&view=list&format=raw&' + results;
$.ajax({
url: url,
success: function(data){
$('#test').html(data);
alert(data);
},
error: function(){
alert('There was an error loading your request. <br />Please try again later.');
}
});
Nothing is written to #test and nothing is displayed in the alert(even though the alert happens). Why for? I should be getting a whole lot of array data, except I don’t even get a lump of coal.
Make sure you’re encoding your php array before echoing it out so jQuery can parse it.