0

I tried to load HTML page with scripts using .load function. But, its not working.

Is there any way to change existing code as AJAX to load complete html page with scripts? We need this script to trigger while changing the contents based on the list item selected.

Thanks HTML

<ul class="choices--sp">
  <li><a href="javascript:;" data-url="global.html">GLOBAL</a></li>
  <li><a href="javascript:;" data-url="australia.html">Australia</a></li>
</ul>

<div id="container">
</div>

JS

$('.choices--sp li a').click(function(){
  $('#container').load($(this).attr('data-url') + ' #ajax--container');
  return false;
});

HTML page to load inside AJAX

<div id="ajax--container">
<section class="component">
    <div class="page">
        Test
        <script type="text/javascript">
            $(document).ready(function () {
                alert(1);
            });
        </script>
    <div>
  </section>
</div>
1

1 Answer 1

0

Not sure about your need.. hope this help

 $('.choices--sp li a').click(function(){
  $.ajax({
            url:$(this).attr('data-url'),  
            type: "GET",
            success:function(data) {$('#container').html(data);}
        });
  return false;
});
Sign up to request clarification or add additional context in comments.

2 Comments

It should be: $('#container').html($(data).find('#ajax--container').html());
Thanks both Sarath & A. Wolff for your great help!!

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.