views:

163

answers:

2

I would like to add a Javascript at the end of some ajax content, It works fine on firefox but internet explorer print the script without running it.

<script type="text/javascript">
    $.tablesorter.addParser({
      id: 'title',
      is: function(s)
      {
        return false;
      },
      format: function(s)
      {
       s= s.substring(s.indexOf('<span class="title">')+24,s.length-30);
        return s.replace(' ','');
      },
      type: 'text'
    });

    $.tablesorter.addParser({
      id: 'price',
      is: function(s)
      {
        return false;
      },
      format: function(s)
      {
       s= s.substring(0,s.length-3);
        return s.replace(' ','');
      },
      type: 'digit'
    });
    $(document).ready(function()
    {
       $("#result").tablesorter({
            headers: {
             0: {sorter:'title'},
             1: {sorter:'price'},
                2: {sorter: false}
            }
       });
    });
    </script>



function submitForm()
{
$("form#search").ajaxSubmit({
      beforeSubmit: function(formData, jqForm, options) {
       $("#window").html('<div style="text-align:center; display:block;"><img src="../images/commun/spinner.gif" /></div>');
       return true;
      },
      success: function(msg, statut) {
       $("#window").html(msg);
       return false;
      }
      });
}
+1  A: 

I've had the same problem, what I did was just put the script content inside of a div with a special classname. Once I get the response back and enter it into the DOM, I pull out that script content and simply eval() it. This works in all browsers :-)

Joel Martinez
+2  A: 

You should use getScript to load and run scripts. You can't mix script with html content. Also make sure that the context-type of the server's response is set to javascript MIME type, like 'text/javascript'.

kgiannakakis