1
I’m creating an application with React, and the back-end part with PHP
I have ajax request:
pesquisaCliente(e) {
e.preventDefault();
$.ajax({
url:'http://192.168.0.109/prontaentrega/pesquisaCliente.php',
contentType:'application/json',
datType:'json',
type:'post',
data:JSON.stringify({nome:this.state.nome}),
success: function(cli) {
}.bind(this)
});
}
and in the PHP part:
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Content-Type");
include 'conexao.php';
echo $_POST['nome'];
?>
Only he doesn’t show the value of $_POST['nome]'
Note: There is no error because they are different servers.
he ta showing it on the screen: Trying to get Property of non-object
– Rodrigo Jacinto
Okay. Execute
echo file_get_contents("php://input")
, Tell me what appears printed.– Pedro Souza
That’s right, the problem is that ajax is waiting for a return json, and since I was just printing the variable in php, it returned html. I think it should be the Act that requires this.
– Rodrigo Jacinto
Great, I’m glad you caught the problem.
– Pedro Souza