tags:

views:

169

answers:

1

Hi,

I want to achieve the really easy task to replace the head node of a page with the head node of the page called with an ajax call.

I do it like this:

        url = 'http://myurl';                    
        $.get(url, function(results){
          var head = $('head', results);

          $('head', results).each (
             function() {
                 alert("got a match ");
             });


          var form = $("form.ajax_form_result", results);
          //update the ajax_form_result div with the return value "form"
          $('head').html(head);
          $('#ajax_form_result').html(form);
        }, "html");

The form updates work without problems, but the head update does not work. $("head", results); does not return a node, resulting in an empty head in the new document.

+2  A: 

try: $("head", $(results));

"results" should just be a block of text in html format. "$(result)" should be that block transformed in DOM objects.

James Curran
I tried it but it does not change anything. Both approaches lead to the same result, an empty head ;-) Whereas I'm sure that my ajax call returns a complete html page with a head tag.
Tom Tom