I know many questions like this are already existing here, but I tried all I found and nothing worked for me.
What I want/tried:
I have ONE wordpress installation and want wo display just a part of one of my pages(page1) on an other page(page2). (it's almost the same like in THIS post) So I try to load a part (div) from page1 into a div of page2 with this code:
<script>
jQuery(function($) {
$( document ).ready(){
$('#qi1').click(function(){
var contentURI= 'http://postbasedesign.com/product/postbase-qi1-cover-design/ #main'; // URL TO GRAB + # of any desired element
$('#showDesigner').load('http://postbasedesign.com/wp-content/plugins/image-map-pro-wordpress/qi1.php?url='+ contentURI, function(responseTxt, statusTxt, xhr){
if(statusTxt == "success")
alert("External content loaded successfully!");
if(statusTxt == "error")
alert("Error: " + xhr.status + ": " + xhr.statusText);
});
});
});
</script>
#showDesigner
is the id of the div
where the html from the div
with the id qi1
should appear.
First I inserted just the url of the page in load()
and it didn't work.
I think it was because the cross domain policy. After a little bit of googeling I found THIS post. So I added a php (qi1.php) at the server with this code
<?php echo file_get_contents($_GET['http://postbasedesign.com/product/postbase-qi1-cover-design/']); ?>
Which gets the content of the page I need, like in the linked post is described.
Now I inserted instead the url this php in load()
(see code above)
What I get:
If I click I get the message "External content loaded successfully!" but in the div nothing happens. It is still empty.
I already tried everything what came into my mind.
I deleted .ready()
, emptied my cache, wrote all $
as jQuery
, switched to position of the code...
But if I try my code above nothing happens. I debugged the code and the functions are called and there is no error in the browser console. But I can't see anything even if the filepath to the file on the server is right and all pages and divs are existing (I checked this several times)
It worked once, but than I changed the code, and now it doesn't. So is there a small mistake which I overlooked or why isn't it working? Maybe the php code is wrong and because of that nothing is displayed. But it was displayed once, so does someone have an idea why?
Why still duplicate?:
*I rewrote the entire question because I think maybe it was not clear. I really don't know how the duplicate should help me..sorry. I have no REST api, I have no flask and I make no http-request. They try there something totaly different, don't they?
Why has the domain no CORS headers? Everything happens on the same domain, so I don't try to access a different domain. I did THIS to avoid accessing a different domain. Is this really the same like in the marked (duplicate) post?*