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

        }
   })   
3
  • 1
    What is your problem? Commented Jan 3, 2015 at 8: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? Commented Jan 3, 2015 at 8:18
  • 1
    Use jq .html() ($('#tabs-2').html(str);) method instead of innerHTML property. If using innerHTML, you would need to eval() js code: stackoverflow.com/questions/1197575/… Commented Jan 3, 2015 at 8:33

1 Answer 1

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
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.