Mehdib92 Posted October 18, 2013 Share Posted October 18, 2013 Hi, I need to get the customers' addresses in json format. I tried to override the AdressesController by adding if(Tools::getValue("format") == "json") $_POST["addresses"] = Tools::jsonEncode($multiple_addresses_formated); and in the tpl $.ajax({ type: "POST", url: "http://localhost/index.php?controller=addresses&id_address="+$(this).attr('id')+"&format=json", success: function(addrjson){ console.log(addrjson); } }); The request works but it return the whole page (with the header, footer, etc...). Does anybody knows how to only retrieve the addresses json object ? thanks Link to comment Share on other sites More sharing options...
NemoPS Posted October 19, 2013 Share Posted October 19, 2013 Where are you adding that first block? Ideally, you should do it in the init() method Furthermore, it should die() once it gets the json string, if you only need that Link to comment Share on other sites More sharing options...
Mehdib92 Posted October 19, 2013 Author Share Posted October 19, 2013 Hi, Sorry I forgot to say that I putted it in the inirContent() function. I have modify my code and it seems to work if(Tools::getValue("format") == "json") { if(Tools::getValue("id_address")) { $id_address = Tools::getValue("id_address"); $address = new Address($id_address); $json_address = AddressFormat::getFormattedLayoutData($address); $json_address["formated"]["id_address"] = $id_address; } die(Tools::jsonEncode($json_address)); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now