tags:

views:

71

answers:

3

I'm trying to get off site content and display it on my web site.

I have site 1 and I want to display some content from site 2 on site 1.

My plan is to use AJAX, on site 1, to load a PHP script, on site 1, that will load the content from site 2 and echo it. Then AJAX would take the echo from the PHP script and display it in a DIV on site 1.

My question is...

Will all the other static content of site 1 wait for the PHP script to fully load and echo it's content before it loads?

OR

Will all the other static content of site 1 load initially, then when the PHP script is finished getting the content from site 2 AJAX will display it in the DIV?

This will all happen on page load.

+1  A: 

Normally it's the second case: page loads first, then you add ajax response to div.

You can write synchronous ajax request which would stop rendering until response received, but that doesn't seem like a good choice to me.

Nikita Rybak
A: 

Perhaps you misunderstand the idea behind AJAX. If not, then I misunderstand your question.

If site 1 runs a PHP script that echoes content from site 2, that PHP script will wait until it gets site 2's content before continuing with the rest of the script. However, if site 1's PHP script sends some JavaScript to the client, then the PHP script on site 1 will run without sending any request to site 2 and that JavaScript will request site 2 for its content.

My apologies if I misunderstand your question.

+1  A: 

If you do it on Page Load, your DOM will render first before displaying the AJAX loaded content. Page_Load means that the function will wait until.. well... the page is loaded.

If you didn't want this to happen you could have the script running AS part of the Page Load, with inline Javascript.

Say your function was in your <head> section.

<head>
  <script type="text/javascript>
    function alertMe() {
      alert("hello world!");
    }
  </script>
</head>

Then at the start of your <body> section, you could call that function.

<body>
  <script type="text/javascript">
    alertMe();
  </script>
  <!-- Other page content -->
</body>

This might not be good practice however, since the other website might not be available, and may cause your entire page to time out or annoy the user because your website is taking longer to load.

It's pretty common practise to load AJAX, AFTER your page is loaded, so I would go with option #1.

Marko