I was using jQuery.load() to load a html page’s content into a lightbox. The most useful thing load does in this instance is turning full html pages into a clean html fragment to be inserted into the page.
But (because of a buggy 3rd party API which won’t work when loaded dynamically), I need to first use a regex to filter out one or two elements from the page before it gets processed as html, which means I need to use the dataFilter option of $.ajax.
So now that I’m using $.ajax instead of .load I need to convert my filtered text into the clean html that .load delivers automatically
But $(response) generates a strange buggy jQuery object where .find(), children() etc… don’t work.
Can anyone tell me how to get the clean html I need (I notice the ajax code injQuery has changed a lot from v 1.4.4 to 1.5 – a solution using either version would do)
Here’s what I have so far (using jQuery 1.4.4) (all the variables and methods referenced are defined above this code)
$.ajax({
url: url,
type: "GET",
dataType: "html",
dataFilter: function (response) {
return response.replace(recaptchaRegex, "");
},
success: function (response) {
// If successful, inject the HTML into all the matched elements
// See if a selector was specified
destination.html($(response).children("#lightBoxForm"));
callback();
}
});
Well I see this was asked a while ago but hopefully this will still be helpful to you. From your question I understand you want to replicate the $.load function with the $.ajax function instead.
A tool you might find useful to use in the future is the jQuery source viewer so you can see exactly how jQuery is doing things under the hood.
And my html