0

I have a php page which has lot's of code of html and javascript inside it.Ihe other page use ajax to send an id to the first page and get the results and put it inside a div element.
Now I want to run those returned codes which contains javascript and html codes. How should that be done?

This is my ajax request to the first page:

       $(document).ready(function() { 
        $.ajax({
        type: "POST",
        url: "showing.php",
        data: "s_id="+s_id+"&submit=true",
        success: function(msg){
        str=$.trim(msg)
         document.getElementById('tabs-2').innerHTML = str;
           document.getElementById("ui-id-2").click();

        }
   })   
sanoj lawrence
  • 951
  • 5
  • 29
  • 69
omid
  • 45
  • 8
  • 1
    What is your problem? – Sadikhasan Jan 03 '15 at 08:13
  • @Sadikhasan Showing.php contains javascript codes and I need to run them after putting the codes inside that div.How should I run those lines? – omid Jan 03 '15 at 08:18
  • 1
    Use jq `.html()` (`$('#tabs-2').html(str);`) method instead of `innerHTML` property. If using `innerHTML`, you would need to `eval()` js code: http://stackoverflow.com/questions/1197575/can-scripts-be-inserted-with-innerhtml – A. Wolff Jan 03 '15 at 08:33

1 Answers1

1

I think event delegation can solve your problem.

Like below:

Use $.on(). Instead of registering events on the element you register on a parent which will not be removed

Ex:

$('#tabs-2').on('click', '#ui-id-2', function(){
   //do something
})