0

I have a html page in which i have a div where i need to load content from another page, which contains javascript and html. if i load as plain html, the html doesn't work.

so is there anyway make the javascript to work the way it has to and the html too when loading it using ajax.

1
  • Is your AJAX-loaded page in the same domain as the main page? Commented Apr 28, 2011 at 12:11

3 Answers 3

2
<script type="text/javascript">
   $(document).ready(function(){   
    $("#myDiv").load("myPage.html");
   });
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, the JavaScript will also work. Run a quick sample on your side to see for yourself. It is simple and you won't need to change a thing.
it works sometimes and sometimes it wont... especially in firefox. dunno why :-S
0

If I'm reading this properly, then you might not be-able to do this, there are all sorts of mechanisms to stop javascript from accessing data from other places, due to security concerns.

However, can you not simply just use an IFrame ?

3 Comments

iframe is easy to do... but i want the content to be loaded in div. thats why!
@Revathy If the content is on a different domain, subdomain or protocol, it will need to be loaded via AJAX instead of with jQuery's load function. Otherwise, you should be OK.
it is in the same domain buddy!
0
$(document).ready(function(){ $('#result').load('ajax/test.html'); });

else try this

$('#result').load('ajax/test.html', function() { alert('Load was performed.'); });

1 Comment

i tried this... but my problem is it loads sometimes but sometimes not. especially in firefox. any idea why? should i check whether the page content has been received and load'em?!

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.