Elaine Marley
Elaine Marley

Reputation: 2243

Changing the content of a div with .html after

After doing so:

        $.ajax({
            type: "POST",
            url: $("#form").attr("action"),
            data: "value=" + value + "&sel=" + sel,
            success: function(data) {
                $("#cont-pag").html(data);
            }
            /*success: function(msg) {
                alert(msg);
            }*/
        });    

I get a big chunk of code (I checked with the alert msg) inside a . I already have a big div cont-pag in my original page, I just want the one from the ajax call to replace the previous one. Am I doing this wrong?

Edit: the structure that's supposed to show up goes like this: I have my query over here and stuff and then...

echo'<div id="cont_pag">    
<ul id="content_pag">'; 
    while($row = mysql_fetch_object($res)){ 
                echo'<li>...</li>';
            }
echo'</ul>'; //here is when my msg will stop painting code, but there's more:
if (mysql_num_rows($res)>8)
echo '<div id="page_navigation"></div><div class="siguiente-pag"><p>'.$cajon_siguiente.'</p></div>
 </div>'; ?>

Ok so I answer that last thing myself. I missed my markup as always:

 echo '<div id="page_navigation"></div><div class="siguiente-pag"><p>'.$cajon_siguiente.'</p></div>';
 echo'</div>'; ?>

And now the alert shows it properly but the .html doesn't replace the original div. May I have a conflicting script somewhere? (it's a complex project and a lot of people work on it and has a few jquery tweaks here and there). Can I do the div replacement differently?

Upvotes: 1

Views: 138

Answers (1)

Raoul
Raoul

Reputation: 3909

Try adding:

dataType: 'html',

To specify what sort of data is being returned. Also consider using Firebug and it's console.log function to check for errors and what is being returned.

Upvotes: 2

Related Questions