Ajax page loading and Scripts contained in these pages

Ajax page loading and Scripts contained in these pages

Hi everyone.

I have a script that automatically convert each forms to Ajax forms. This script do the form submission with the "serialize()" function and then extract a part of the response and append it to the page.
This script works fine but many of our pages contains scripts in page header so I want to also load theses scripts to the page but I don't know how to do that. I have tried to obtains the scripts with "$response.find('script').text()" but the result is 'null'.

Thanks

  1. $('form[action=\''+window.location.pathname+'\']').each(function(){
  2.         var $form = $(this);
  3.         $form.submit(function(event){
  4.                 $.save();                
  5.                 event.preventDefault();            
  6.                 $.ajax({
  7.                     type: $form.attr('method'),
  8.                     url:  $form.attr('action'),
  9.                     data: $form.serialize(),
  10.                     dataType: 'html',
  11.                     success: function(resp) {
  12.                         var $response = $(resp);
  13.                         $("#content").empty();
  14.                         $("#content").append($($response.find("#content").html()));
  15.                         $("#content").trigger('change');
  16.  
  17.                          // Load and eval the scripts contained into $response

  18.                         initPage();
  19.                         $.unblockUI();
  20.                     }
  21.                 });               
  22.                 return false;
  23.             });
  24.     });