Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nette does not receive array #202

Closed
petrparolek opened this issue Jan 14, 2021 · 3 comments · Fixed by #224
Closed

Nette does not receive array #202

petrparolek opened this issue Jan 14, 2021 · 3 comments · Fixed by #224
Labels

Comments

@petrparolek
Copy link

petrparolek commented Jan 14, 2021

Naja version: 2.1.2

JS:

            year = '2020';
            paymentTags = {1,2};

            data = { year, paymentTags };

            naja.makeRequest('GET', "/?do=paymentsJS-changeYear", data)

obrazek

Nette receives

obrazek

@jiripudil
Copy link
Member

Reposting my thoughts from #207 for reference:

Since this issue is already on the table, I'd like to have it fixed properly, i.e.

  • Naja should transform everything that PHP and/or Nette can correctly parse, including arrays (key[]=value), objects (key[subkey]=value), and any arbitrarily nested structures (key[subkey][0][subkey]=value).
  • In addition to GET and HEAD requests where data need to be serialized into the query string, the same transformation also needs to be done to application/x-www-form-urlencoded request body – currently it suffers from pretty much the same bug on this line.
  • Needless to say, this kind of change needs a decent test coverage.

@petrparolek
Copy link
Author

petrparolek commented Jan 20, 2021

Based on last posts about Naja I invent elegant solution of my problem without any changes in Naja :

            data = { year, paymentTags };
            var dataString = JSON.stringify(data);
            console.log(dataString);

            naja.makeRequest('GET', {link changeYear!}, { paramsJson: dataString}, { dataType: 'json'})

and in PHP:

	public function handleChangeYear(): void
	{
		if ($this->presenter->isAjax()) {
			$paramsJson =$this->presenter->getParameter('paramsJson');
			$params = Json::decode($paramsJson);
			bdump($params);
			$year = (int) $params->year;
			bdump($year);
			....
		}
	}

@jiripudil
Copy link
Member

I've released the fix in 2.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants