I am using jQuery AJAX to get new content from the server. Data is loaded in JSON:
$.ajax({ url: url, data: { 'ajax': '1', }, dataType: 'json', success: somefunction });
For server side restriction, I cannot configure more JSON variables inside, so I have to load all the content. This is why I have to load the result in jQuery, than to search and replace some elements on the page like this (used in somefunction ):
var somefunction = function(data) { var con = $('<div></div>').html(data.content);
EDIT: Please note that I must follow the same process to replace three divs!
This is more, but, for example, enough, I hope. My question is: for some logical reasons, I expect the result of loading to the DOM ( $(data.content) ), parsing by html ( con.find('dix#ajax-content').html() ) and back to the DOM ( $('div#mainContent').html() ) it seems to me how to lose some resources and reduce performance I would like to know if there is a faster way to do this and load the DOM directly, for example:
$('div#mainContent').dom(con.find('div#ajax-content').dom());
I tried to do this, but maybe I don’t know what to enter. Also, jQuery documentation didn't help me much.
Some facts:
- jQuery 1.9.1
- JQuery UI 1.10.3 Available
Finally, I know that it would be much better to do something with the server application in order to provide more JSON variables, however I need to write a not-so-simple world of code that takes more time to develop I don’t have right now. Doing this on the client side would be a temporary solution at the moment, however I do not want to significantly reduce performance.
Side question:
Is it right to use the find() function in this case, or is there some better one?
EDIT 2 (syntax line does not work) I expect this to work, but it is not:
content = '<div id="ajax-title">Pečivo běžné, sladké, slané</div> <div id="ajax-whereami"><a href="/category/4">Chléba a pečivo</a> » Pečivo běžné, sladké, slané</div>'; $(content);