I'm trying to send text that is typed via ajax to a php page that will make a query using that text that is received. I want to know how to send the value of nmCliente
to the php page. I tried the following code and the return was 500 (Internal Server Error)
. I'm using the framework Symfony
Follow the codes.
Jquery
var nmCliente = $("#nome").val();
$.ajax({
url: "../buscacliente",
type: "POST",
data: nmCliente,
dataType: "text"
}).done(function(resposta) {
console.log(resposta);
}).fail(function(jqXHR, textStatus ) {
console.log("Request failed: " + textStatus);
}).always(function() {
console.log("completou");
});
PHP
/**
* @Route("/buscacliente", name="busca_cliente")
* @Method({"GET", "POST"})
*/
public function buscaContratoAction(Request $resquest)
{
if ($request->isXMLHttpRequest()) {
return new JsonResponse(array('data' => 'this is a json response'));
}
return new Response('This is not ajax!', 400);
}