Используйте этот хитрый код;)
/*this will get the body content and head by replacing them with div before placing them inside the jQuery factory witch will avoid all bugs, i used this while creating the ajaxit jquery plugin :) */
$.ajax({
type: "GET",
url: $(this).attr('href'),
async:true,
error:function (event, request, options, error) {
if (ajaxItMain.onError){
ajaxItMain.onError(event,request,options,error);
}
},
success: function (data) {
// ----------------- < data >
// clearing CDATA
data=data.replace(/\<\!\[CDATA\[\/\/\>\<\!\-\-/gi,'');
data=data.replace(/\/\/\-\-\>\<\!\]\]\>/gi,'');
// extracting the the head and body tags
var dataHead = data.match(/<\s*head.*>[\s\S]*<\s*\/head\s*>/ig).join("");
var dataBody = data.match(/<\s*body.*>[\s\S]*<\s*\/body\s*>/ig).join("");
var dataTitle = data.match(/<\s*title.*>[\s\S]*<\s*\/title\s*>/ig).join("");
dataHead = dataHead.replace(/<\s*head/gi,"<div");
dataHead = dataHead.replace(/<\s*\/head/gi,"</div");
dataBody = dataBody.replace(/<\s*body/gi,"<div");
dataBody = dataBody.replace(/<\s*\/body/gi,"</div");
dataTitle = dataTitle.replace(/<\s*title/gi,"<div");
dataTitle = dataTitle.replace(/<\s*\/title/gi,"</div");
// comments
var commentPattern = /\<\!\-\-([\s\S]*?)\-\-\>/ig;
// get head comment tags
var headComments = dataHead.match(commentPattern);
// get body comment tags
var bodyComments = dataBody.match(commentPattern);
// head - body - title content
var $dataHead = $(dataHead);
var $dataTitle = $(dataTitle);
var $dataBody = $(dataBody);
}
});
}