0
I want to send an array via jQuery using Ajax to another PHP file, but I don’t know how to access it in PHP.
I’m sending by GET
I don’t know if that would be ideal either.
nome_receita
is a variable and ingredientes
is the array I need to "open" in PHP.
$.get("http://localhost/estudos/oquetemprahj/servidor.php?nome_receita="+nome_receita+"&&ingredientes="+ingredientes+"",function(retorno)
{
alert(retorno);
});
Use console.log(return); and see the output in the browser console, to capture in php will depend on the type of request, in your case vc is using $.get(), get is captured by
$_GET['nome_receita']
. if you want to display the return, you need to give an "echo" on what was sent.– Ivan Ferrer
The ideal is that you use the POST method, and have this return in json. The get method is recommended for relatively fast requests, and they need to preserve variables in the url.
– Ivan Ferrer
You can’t send a javascript array via get, it doesn’t work that way, you have to convert that array before sending, using serialize / unserialize, or send the json object structure via POST. Or convert this variable into a string:
JSON.stringify(ingredientes)
– Ivan Ferrer