0

i'm using this code to load a php page inside a html page using javascipt , but it doesn't work. the code is below :

<html>
....
<div id="home" style="background: #000;background-image: none;height:100%;"></div>
    <script>
    $('#home').load('http://www.website.com/file/index.php').trigger("create");
    </script>
</html>

the php file exists and works fine but it doesn't show up in the actual page . If you have modification i can make i'll be thankful

2
  • 1
    Is it actually returning the data? With firefox/chrome developer tools (F12), check the data being returned in the call. Commented Dec 19, 2013 at 1:54
  • access oigin null thing ... again i don't know to solve this Commented Dec 19, 2013 at 2:07

2 Answers 2

3

If you remote website is not in same server you can't do it, for same-origin policy security restrictions, as specified in the load() documentation.

But, you will have a proxy script like:

proxyScript.php

<?php echo file_get_contents("http://www.website.com/file/index.php"); ?>

And, now, you can: $('#home').load('proxyScripts.php').trigger("create");

Or you will configure your remote server to accept remote request, read: How to use Cross domain Ajax request

Sign up to request clarification or add additional context in comments.

Comments

0

I think it has something to do with javascript happening AFTER php happens.

Why not switch it with

include('http://www.website.com/file/index.php');

if your hiding that div you could just use javascript to show / hide the div based on what ever happens. Dont try to lead the php file when its hovered or clicked or w/e. Load it first and just display it with js.

2 Comments

when i put include instead of load . all the page changes , but that div is inside menu and buttons in bottom .
I don't think I can help more without see'ing the page or the correct code. =[

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.