Jump to content

Ajax call with parameters


Recommended Posts

Hi,

I want to make an ajax call with parameters from a module, but it is being impossible. This is my JS code:

var url = "moduleURL"; // from tpl with getLink(...)
var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200)
    console.log(this.responseText);
  else
    console.log("Bad: " + this.status + " - " + this.readyState);
};

xhttp.open("GET", url, true);
xhttp.send("test=test1"); // With simple passing, not JSON, which I tried too

PHP code:

class SendfilelistModuleFrontController extends ModuleFrontController {
    public function initContent() {
        $this->ajax = true;
        parent::initContent();
        
        $value = Tools::getValue("test");
        $mitest = "Good: " + $value;
        echo $mitest;
    }
}

 

I have been trying some calls, and it works with simple things, as return a string. But if I want to pass some parameters and then retrieve, I can't. I have tried with "Tools::getValue("test")", but it didn't work. In fact, it doesn't return "Good: null", it returns 0. Any idea?

Thanks in advance.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...