Plummer
Plummer

Reputation: 6688

AJAX error handling/checking

I'm using a method that I've used in another site. I don't know why, but AJAX keeps going to error posting "Arraynull". I understand this means "array is null", but when I run the mysql statement, I get plenty of results.

the data is built from a MVC component in Joomla, query, as I'm testing it, is super simple.

function loadOpenhouse() {
    $db = JFactory::getDBO();
    $query = "
        SELECT *
            FROM ".$db->nameQuote('#__mls').";";
    $db->setQuery($query);
    $openhouse = $db->loadRowList();
    echo $openhouse;
}

Then the view just puts it into JSON and echos it.

function display($tpl = null) {
        $model = $this->getModel();
        $array = $model->loadOpenhouse();
        echo json_encode($array);
}

Again, simple AJAX call...

function runQuery(){

var url = 'index.php?option=com_singleprop&view=raw&format=raw';

$.ajax({
    url: url,
    dataType: 'json',
    success: function(data){ 
        $('#prop_details').append(data);
    },
    error: function(jqXHR, error, errorThrown) {  
            alert(jqXHR.responseText); 
    }
});

};

But in the alert I keep getting "Arraynull". The array should not be null. When I run the query in CMD, I get values.

Upvotes: 0

Views: 148

Answers (1)

Musa
Musa

Reputation: 97672

Instead of echoing the query result return it.

return $openhouse;

Upvotes: 1

Related Questions