koyuki
koyuki

Reputation: 75

use of .html in jQuery question?

I am trying to load my controllerMostrarMayorContenido in to an area(div ) on my page(index) and I can load pure text all, I read that It is using .html, It just retrieving the contents of my controller and paste it in index.php, I already do it in mootools but I dont find a way in jquery, It does not work

the problem is with this line document.getElementById('divrespuesta2').innerHTML= texto;

in moootools It works

  var prueboRequest = new Request({
   method: 'POST',
//   data: 'id_tema='+id_tema,
   url: '../controller/controllerTema/controllerMostrarMayorContenido.php',
   onRequest: function() {}, 
   onSuccess: function(texto, xmlrespuesta){
   document.getElementById('divrespuesta2').innerHTML= texto; this line

   },
   onFailure: function(){alert('Fallo');}
}).send();
}

in jQuery no

function limpiarDiv(id_tema){
     document.getElementById("divrespuesta2").innerHTML="";
     document.getElementById("divrespuesta3").innerHTML="";

        $.ajax({

            type: "POST",
            url: '../controller/controllerTema/controllerMostrarMayorContenido.php',
            beforeSend:function(){alert('ejecutandose');},
            success: function(){
                //document.getElementById('divrespuesta2').innerHTML= texto; 
                $('#divrespuesta2').html('texto');
            }
        });

}

Upvotes: 0

Views: 125

Answers (2)

ShankarSangoli
ShankarSangoli

Reputation: 69905

The first argument in the ajax success handler is the response returned by the server resource. Try this

function limpiarDiv(id_tema){
     document.getElementById("divrespuesta2").innerHTML="";
     document.getElementById("divrespuesta3").innerHTML="";

        $.ajax({

            type: "POST",
            url: '../controller/controllerTema/controllerMostrarMayorContenido.php',
            beforeSend:function(){alert('ejecutandose');},
            success: function(response){
                //document.getElementById('divrespuesta2').innerHTML= texto; 
                $('#divrespuesta2').html(response);
            }
        });

}

Upvotes: 0

Soufiane Hassou
Soufiane Hassou

Reputation: 17750

A couple of problems in your jquery code:

  • It should be $('#divrespuesta2').html(texto); since you want the value of texto and not texto as text
  • You need to pass texto to your success callback function, it should look like this: success: function(texto) { ... }

Upvotes: 3

Related Questions