jnunezv Posted June 14, 2019 Share Posted June 14, 2019 Hello. Im putting into practice a tutorial I found in a project. I need to make an Ajax request and recive a variable from the the php file, but instead I recieve the html data of the website. Can anyone help me finding a solution? This is my js file. function change1(link) { console.log("Ajax: OK"); console.log('....'); $.ajax({ type: 'POST', dataType : 'json', url: link, cache: false, data: { variable_1 : 'test', ajax: true, }, success: function (data, status) { console.log(status); console.log(data); }, error : function (hx, status) { console.log(status); } }); } This is my target php file for the ajax <?php class MycustommoduleAjaxModuleFrontController extends ModuleFrontController { public function initContent() { $this->ajax = true; parent::initContent(); } public function displayAjaxdoSomeAction() { $var1 = Tools::getValue('variable_1'); echo "<script>console.log(".$var1.")</script>"; die(Tools::jsonEncode(array('result' => "test"))); } } ?> This is the result in the console log. As you can see, the returned data is a lot of html and not necessary the result => test, I was hoping for. 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