Organize incoming date and change, jquery

Asked

Viewed 57 times

1

I get two Ivs from the server that way:

 <div id="1"></div>
 <div id="2"></div>

However these documents already exist on the page, so I just wanted to update their proper contents, I receive them from an AJAX request, how to do them?

  • Can you explain it better? then you get this HTML from the server but there are already Divs with this ID and you want to replace the HTML in the ones that already exist with the ones that come from the server?

  • @Sergio that’s right..

1 answer

1


What you can do is search inside that server response for the elements and iterate to remove the ID. I think it will work even though ID have to be unique.

But the best thing was for the server to return a JSON with for example:

`{ "umaID": "html", "outraID": "html, etc...`

But using what you have and what’s in the question, test like this:

$.ajax({
    url:"teste.php",  
    success:function(data) {
        $(data).find('*').each(function(){
            $('#' + this.id).html(this.innerHTML);
        }); 
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.