0

I have some js that does an autocomplete:

jQuery("#city").autocomplete({
    source: "/route/to/countroller",
    minLength: 1,
    select: function( event, ui ) {
        if((typeof ui.item.province !== 'undefined')){
            jQuery("#city").val(ui.item.city);
            jQuery("#region_id").val(ui.item.province);
        }
        else{
            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 Jun 18 '16 at 13:46
0

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, privacy policy and cookie policy

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