Jump to content

jnunezv

Members
  • Posts

    1
  • Joined

  • Last visited

jnunezv's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. 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.
×
×
  • Create New...