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
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
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.
Related
Im trying to include php(html) file in my website. All pages are loaded with jquery/ajax into a div. Im trying to load another website on my server into the div using php include, For my clients to transfer files to my administrative team. My code isnt working. and How do I keep the website inside the div when the users start clicking around inside of the client portal (web site on my server) without forwarding them out of the window. I dont want to use an iframe so can this be done with jquery or javascript?
Visit my website for a live view https://trillumonopoly.com
Heres the code:
<div id="page1"></div>
<script>$("#page1").load("https://trillumonopoly.com/clients/index.php body");</script>
</div>
You can just use the PHP include command.
<?php include "file.php" ?>
I have a PHP file which deals with registration on a site, currently once the user has registered they are redirected to the home page and a success message states that the user's registration has been successful.
I would like to change this to a jquery notification.
Is it possible for me to include jquery within this registration PHP file?
For example.
<script type="text/javascript" src="js/jquery_v_1.4.js"></script>
<script type="text/javascript" src="js/jquery_notification_v.1.js"></script>
If I place this at the top of the page before the PHP tags commence.
If this is not possible, what is the best way to overcome this obstacle?
Thank you
Yes that is fine, as long as they are outside of the <?php ?> tags
Yes you can do it. just be careful not to put any javascript/html (any output, not even space) code before header or session_start functions, cause these will cause problems if anything is printed before they run.
is there a way to make a redirection from inside a phtml file in ZF2 Framework?
The reason is that I am using the jQuery $.POST mechanism (ajax) to refresh a part of the page, but I cannot make a redirection from the controller used by the ajax because it will load the new page into the div (which is inside another page).
I have tried using ZF2's :
$this->_redirect($this->url('restaurants'));
But I get a ServiceNotFoundException. I also tried php's:
<?php header( 'Location: http://www.yoursite.com/new_page.html' ) ; ?>
But this just did not work at all.
Hope this is clear enough!.. Any help is much appreciated!
You can't use header when you printed anything before it. There must not be any output before header. So this means the exact same for $this->_redirect().
What you could do is the following:
Add this to your head section
<meta http-equiv="refresh" content="0; url=http://example.com/">
or use javascript to redirect the user. If you don't want to extend your layout file you should use javascript:
<script type="text/javascript">
window.location = "http://www.example.com/"
</script>
EDIT
After rereading your question i think the only possible way for you to redirect the user after you've received the page content is the javascript solution.
How can I get a html element from another website directly into my site (not using an iframe).
For Example:
A page on another website has the following code (and nothing else);
<p>example text</p>
how can I get this into my website to be able to edit it. I can't directly copy the code because I want the code on my site to change in conjunction to the other site.
As you seem to have PHP tag, so if using PHP, you can use file_get_contents(), like
$html = file_get_contents('url_of_site/page.html');
or with DOMDocument, like:
$doc = new DOMDocument();
$doc->loadHTMLFile('http://some_site.com/');
$html = $doc->getElementsByTagName('p');
print_r($html);
Note:: Due to Same Origin Policy, you cant do it with just javascript. If you want to do it with Javascript you need to create a proxy kinda stuff, like have a test.php file in your own server, add code to fetch content from other site into test.php file, and call this test.php file using javascript ajax.
I have dynamic forms in my urls .i want to write a javascript such that when the users paste that javascript in their web pages the form should dispay.
<script type="text/javascript">
window.location.href = "http://myserver/2a249ccf59e272abb8e7b8582560a45c"
</script>
The problem is using the above code , The url redirects.I want to avoid redirection
I'v tried iframes , but i dont want to use them as per requirements .
You need to use AJAX to fetch a remote page. You must get the page from the same server that your webpage was delivered from to avoid same origin policy issues.
I would recommend using a library to handle AJAX requests. jQuery has AJAX functions built in, but you could use others also. With jQuery...
// be sure to include jQuery library in the head of your document...
// general wrapper to execute code only after all page elements have loaded
$(function(){
$.get("http://myserver/2a249ccf59e272abb8e7b8582560a45c",function(data,status){
// put the fetched data (your html form) at the end of the existing body content
// you could put it somewhere else by changing the `body` selector
$("body").append(data)
})
})