ricardo
ricardo

Reputation: 1581

javascript jquery response HTML into a div do not retrieve all HTML

I am doing a Ajax call with jquery and putting the content inside a div like this:

$('#replace').html(response);

But it is not replacing all the content I got from 'response'.

When I do :

alert(response)

I see all the HTML code with no problem.

But when I do:

$('#replace').html(response);

It does not put all the HTML code from response.

When I do an alert

alert(response);

I got this (which is correct):

#
    <div id='replace'>      
            <tr onclick='javascripot:gravaJOBparaView(5746);' ondblclick='fnOpen(5746);' >
                      <td class='preview' title='8746' >8746</td>
                      <td>XXXX</td>
                      <td>xxxxx</td>
                      <td>xxxx</td>
                      <td>xxx</td>
                  <td>xxxxx</td>
                  <td title='xpto'>XXXXXX</td>
                  <td></td>
                  <td> <br/>18:00</td>
                  <td>22/07/2012</td>
                  <td title='Check XXXXX' class='popups' ><a href='#popup_5746'><img src='xpto.png'  alt='Check XXXXXX' width='40px'></a></td>

        </tr>   
  </td>

#

But When I do the:

$('#replace').html(response);

It puts this code in the div 'replace':

#
   <div id="replace">       

                  8746
                  XXX
                  XXXX
                  XXXX
                  XXXXX
                  XXXXX
                  RXXXXXX

                   <br>18:00
                  22/07/2012
                  <a href="#popup_5746"><img width="40px" alt="Check XXXXX" src="xxxxxx.png.png"></a>
  </div>
#

As you can see for some reason it does not put all the tags from response.

What should I do?

Upvotes: 0

Views: 215

Answers (3)

Ali Abbas
Ali Abbas

Reputation: 4277

Your HTML isn't valid. <tr> must be in a table tag. Replace

<div id='replace'>

by

<table id='replace'>

Replace the last </td> by a </table>

http://jsfiddle.net/wk4eD/1/

Two element must not have the same id in your page

Upvotes: 2

Travis Watson
Travis Watson

Reputation: 1749

You need to mind the html nesting rules. <td> must be inside a <tr> which must be within a <table> (technically you need a tbody or thead, but browsers are tolerant of this one).

You should use this service: http://validator.w3.org/#validate_by_input

Under More Options, choose to validate HTML fragment and match your doctype. You can use that to make sure the HTML is valid before trying to stuff it into that div.

Upvotes: 1

user1269989
user1269989

Reputation: 117

you have to close the div you might want to use

 </tr> 
  </div>  
  </td>

at the end. JQuery might replace text before
because it cannot find proper div end statement.

Upvotes: 0

Related Questions