Execute javascript after XMLHttpRequest?

Hello,
I got a javascript function to pull contents from a php page, let’s call this page B to the actual page, let’s call this page A.
As I know when a page gets loaded the javascript on that page won’t execute, am I right?

Now I need the javascript code on that page B to get executed.

Is that somehow possible?

You can load the page into an iframe (it doesn’t need to be visible) and the retrieve the contents after it has loaded.

Note: You may have issues if page B is from a different domain.