I am doing tests for an application. I want to make an ajax request with jquery to a php file and receive an xml structure from it.
The request with Jquery I do so:
$.post({
url: 'php/procesar_xml.php',
dataType: 'xml',
})
.done(respuesta)
.fail(error);
function respuesta(datos) {
console.log(datos);
}
That a simple request that does not send data or anything. I just want to receive the xml structure. I have the php file defined as follows:
<?php
header('Content-Type:text/xml');
$xml='<?xml version="1.0"?>';
$xml.='<TRABAJADOR>';
$xml.='<ID_TRABAJADOR>123456</ID_TRABAJADOR>';
$xml.='<NOMBRE_TRABAJADOR>juan</NOMBRE_TRABAJADOR>';
$xml.='</TRABAJADOR>';
The request returns the following error message:
Mensaje de error Error: Invalid XML:
<?xml version="1.0"?><TRABAJADOR><ID_TRABAJADOR>123456</ID_TRABAJADOR><NOMBRE_TRABAJADOR>juan</NOMBRE_TRABAJADOR></TRABAJADOR>
I have tried several ways but it always gives me the same error. What can you owe? Greetings.