2010-02-15 2 views
3

페이지의 헤드 노드를 ajax 호출로 호출 된 페이지의 헤드 노드로 바꾸는 작업을 정말 쉽게 수행하고 싶습니다.

 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"); 

양식 업데이트가 문제없이 작동하지만 헤드 업데이트가 작동하지 않습니다

나는 같은 해. $ ("머리", 결과); 노드를 반환하지 않으므로 새 문서에서 머리가 비어 있습니다.

+0

안녕하세요 톰 탐, 혹시 이것을 알아 냈습니까? 나는 지금 당장 똑같은 문제에 봉착하려고 노력하고있다. –

+0

아니요, 마침내 헤드 노드를 대체하는 또 다른 솔루션이 필요하다는 결론에 도달했으며 문제를 재구성하여 더 이상 헤드 노드를 다시로드 할 의무가 없었습니다. 아직도 내가 머리가 항상 비어있는 것은 궁금 할 것이다. –

답변

1

시도 : $("head", $(results));

"결과는"단지 HTML 형식의 텍스트 블록이어야한다. "$ (result)"는 DOM 개체에서 변형 된 블록이어야합니다.

+0

나는 그것을 시도했지만 아무 것도 바뀌지 않았다. 두 가지 접근 방식 모두 같은 결과를 낳습니다. 빈 머리 ;-) 내 Ajax 호출이 헤드 태그가있는 완전한 html 페이지를 반환한다고 확신하는 반면. –

0

이 나를 위해 잘 작동 : 당신이해야 할 일을 할 수 있어야

var feed = http://www.feed.com/page.html; 

jQuery.get('http://yourdomain.com/proxy.php?url='+feed+'', function(html){ 
    if (html == '') { 
     alert('Invalid URL'); 
     return false; 
    } 

    html = html.replace(/<(\/?)(html|head|body)([^>]*)>/ig, function(a,b,c,d){ 
     return '<' + b + 'div' + (b ? '' : ' data-element="' + c + '"') + d + '>'; 
    }); 

    RSSlink = jQuery(html).find('[data-element=head]').find('link[type="application/rss+xml"]').eq(0).attr('href'); 

}); 

!

0

나는 내 문제에이 솔루션을 구현했습니다 :

var myUrl="http://urlExampleSubstituteWithYour" 
$.get(url, function(data) { 
    // Get the string index of the content of the start head tag 
    var startHead=(data.toString().indexOf("<head>"))+6; 
    // Get the string index of the finish head tag 
    var stopHead=data.toString().indexOf("</head>"); 
    // Create a string of the head content of the myUrl page 
    var head=data.substring(startHead+6,stopHead); 
    // Apply HTML to my block... 
    $("#idOfMyBlock").html(head); 
}); 

이 솔루션은 (아마 최고의하지 않음) 저를 저장했다! 영어로 죄송합니다!

관련 문제