I have some js that does an autocomplete:

    source: "/route/to/countroller",
    minLength: 1,
    select: function( event, ui ) {
        if((typeof ui.item.province !== 'undefined')){
            alert("Nothing selected, input was " + this.value );

I know the the controller gets hit, because i've debugged all of it and up until the point where i return results, everything works as it should work.

When I return the results, I do it like this:

return Mage::helper('customerdetails_addressvalidation/autocomplete')->jsonEncode($suggestions);

However, the suggestion dropdown under the input never appears to give me the options returned by the controller.

I know that the code works because I previously had the autocomplete JS source option pointing to a file in my magento root (for testing), and the suggestions were returned without a problem.

Is there some trick/special way to return the suggestions from a controller, as opposed to a file in the route?

  • Can you see the JSON that is returned by the controller in your browser console?
    – 7ochem
    Commented Jun 18, 2016 at 13:46

1 Answer 1


The solution was that instead of returning the suggestion like this:

return Mage::helper('customerdetails_addressvalidation/autocomplete')->jsonEncode($suggestions);

I had to echo it back like this:

echo Mage::helper('customerdetails_addressvalidation/autocomplete')->jsonEncode($suggestions);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.