0

im trying to load a specific div from a different webpage.

<div id="result">Loading</div>

<script>
        $( "#result" ).load("http://bte.gep.msess.gov.pt/pesquisa_avancada.php #boxinterior" );
        </script>

I already tried with jquery and with javascript but its not working properly, as it should. Any ideias? The #boxinterior is the div from the other website.

EDIT

its not showing me the div as it should and its giving me a

XMLHttpRequest cannot load http://bte.gep.msess.gov.pt/pesquisa_avancada.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

1

1 Answer 1

3

Per your edit, you aren't allowed to client-side load content from other domains for security reasons.

If you want that content injected into your page, you should load it server side and include it with the response.

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

7 Comments

I already managed to show the full webpage with <object data="url"></object>. is it possible to just show a div from that object?
@V.David I believe the issue there is that client-side you would not be allowed to script against the content inside an object or iframe etc., again for security reasons. The content you are loading would have to provide an API.
@V.David Are you currently running any server-side logic? You should be able to execute a web request for the resource and then extract the target div and inject it in your page. Or set up an end-point on your server that simply passes that resource through (a proxy of sorts) and then the .load will be accessing your domain.
No im not, im using wordpress. But im just trying to make some tests with a normal html file. (Sorry if i said anything stupid, kinda newb)
@V.David Really all good - everyone is new at some point, and this is an exceptionally common wall. If you're using WordPress, you should be able to use PHP to achieve what I described. You won't be able to do it with pure JavaScript without cooperation from the resource you're trying to consume.
|

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.