What should be the return value from my AJAX procedure?

I need to return XML from ajax, but it is not working. I have a header in the main file (the one that makes the ajax call), which is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

In this file I have this code:

function confirmarordendetrabajo(){
      if ( $("#inputcondiciones").attr("disabled") ) {
            alert ("Orden de trabajo ya fue generada");
        var condiciones = escape($("#inputcondiciones").val());
        var accesorios = escape($("#inputaccesorios").val());
        var mantenimiento = escape($("#inputmantenimiento").val());
        var ncliente = $("#ncliente").val();
        var fecha = $("#xfecha").html();
        var noplaca = $("#element_1").val();
            type: "GET",
           url: "ln_taller.php",
            data: "funcion=3&ncliente="+ncliente+"&fecha="+fecha+"&nomanual=0&nocliente=0&marca=-1&tipoaparato=-1&modelo=-1&serie="+noplaca+"&condicion="+condiciones+"&accesorios="+accesorios+"&defecto="+mantenimiento+"&clientegarantia=0&garantia=0&fechacompra="+fecha+"&almacencompra=0&nfactura=0",
            dataType: "json",
                    alert ("Orden de Trabajo  fue generada satisfactoriamente");


the code in BOLD, is where I call the ajax function.

the ajax file is: (ln_taller.php)

  class ln_ordendetrabajo{
      function guardar_boleta($ncliente,$fecha,$nomanual,$nocliente,$marca,$tipoaparato,$modelo,$serie,$condicion,$accesorios,$defecto,$clientegarantia,$garantia,$fechacompra,$almacencompra,$nfactura){

//this file contains the code needed to connect to MySQL.

            $con = new conectar;
            $sql = "select ifnull(max(norden),0)+1 as sig from ordenes_de_trabajo where id_empresa = " . $_SESSION["idempresaactual"];
            $conf = $con->ejecutar($sql);
            $row = mysql_fetch_array($conf);
            $norden = $row["sig"];

           $query = "insert into ordenes_de_trabajo(norden,id_empresa,id_sucursal,id_sucursal_actual,id_cliente,fecha,nomanual,nocliente,marca,tipoaparato,modelo,serie,condicion,accesorios,defecto,cliente_garantia,garantia,fecha_compra,almacen_compra,nfactura) values('".$norden."','".$_SESSION[idempresaactual]."','".$_SESSION[idsucursalactual]."','".$_SESSION["idsucursalactual"]."','".$ncliente."','".$fecha."','".$nomanual."','".$nocliente."','".$marca."','".$tipoaparato."','".$modelo."','".$serie."','".$condicion."','".$accesorios."','".$defecto."','".$clientegarantia."','".$garantia."','".$fechacompra."','".$almacencompra."','".$nfactura."')";

            echo "{'success':'1','norden':'" . $norden . "'}";
  $a= new ln_ordendetrabajo;
  $funcion = $_GET[funcion];
      case 3: $a->guardar_boleta($_GET[ncliente],$_GET[fecha],$_GET[nomanual],$_GET[nocliente],$_GET[marca],$_GET[tipoaparato],$_GET[modelo],$_GET[serie],$_GET[condicion],$_GET[accesorios],$_GET[defecto],$_GET[clientegarantia],$_GET[garantia],$_GET[fechacompra],$_GET[almacencompra],$_GET[nfactura]);

The query in bold is executing fine, but the value of norden and of success, don't seem to be returning into the main file. Its supposed to show the alert. I have several functions that work fine, but in these I'm not using the header described in here.

The reason why I use these headers, is because it uses a good format for displaying.

Thanks, please ask me to clarify and I will respond as soon as possible.

Thanks experts.
Who is Participating?
>I need to return XML from ajax,

So why dataType: "json", ?

put this in the front of your file

header('Content-Type: text/xml'); 
echo "<?xml version=\"1.0\"?><root>";

Open in new window

use a loop to read all the row and use an echo similar to this one :
echo "<tag>" . $row["field"] . "</tag>";

Open in new window

at the end, add the end tag of the root tag, for example :
echo "</root>";

Open in new window

aguisaAuthor Commented:
Sorry for the question, but what should I write instead of json?

aguisaAuthor Commented:
Thanks for all the support. Super useful.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.