I'm trying to get the source code from this page, to get the code of the timetables, and then parse it.
But when I fetch it with file_get_contents, the div I'm looking for is empty. I searched in the code, and it looks like it's filled with jQuery when to body is loaded.
So my question is : how can I get the source code of the page after the jQuery is executed ?
Thanks.
Since jQuery is javascript, php's file_get_contents will not help because it does not execute javascript.
Either find out which ajax data they load and use them directly, or use a browser ;)
the information you want comes from this page http://www.cinesion.ch/cinesion/timetable.php through an AJAX request so file_get_contents will never get it unless you do the call directly to this page...
try this one
http://www.cinesion.ch/cinesion/timetable.php?date=%&movie=%&city=%&_JEXEC=1
Related
There is 1 empty HTML page. When you open it jquery write in page. HTML with 2 div looks like,
<div id=1>html1</div>
<div id=2>html2</div>
When u view using F12, then page its empty.(page is not empty but showing empty) and curl or file_get_content returning empty
my problem is how to get information in div with php api( curl or file_get_contents)
Sorry about my English. Please try to understand and help me.
Unfortunately that is not possible.
The curl request will not execute the javascript, so the HTML will not appear in the response.
What you might want to do is to use curl or file_get_contents to get the javascript which creates the HTML.
I'd like to pass some data from PHP to JavaScript without JSON.
The reason is because I don't want the data been readable by anyone if clicks on view page source.
So, I have a PHP like
print(<script type="text/javascript">a = "aaa";</script>);
In my HTML code this will be
<script type="text/javascript">a = "aaa";</script>
I can remove this in the client side, after loading the variable. By for example with jquery
$('script[type="text/javascript"]').remove();
And after the DOM will not have anymore the script tag, but the variable a.
Later if I type to the console window.a will be aaa.
But i do not want to show the <script type="text/javascript">a = "aaa";</script> in my HTML source code. Is this possible, to pass the PHP variable directly to the DOM?
Thanks for the help.
JavaScript is a client-side language. Whatever you pass to it (by whatever means) will be readable by the end user.
Removing the Script DOM won't help, as "view source" shows the HTML code as it was during download. If that is what you are concerned about, you can fetch the variable via an AJAX once the DOM has been loaded.
(But it still is readable by anyone who can read JavaScript (an re-run the AJAX call), use Firebug or Wireshark. It really only helps against a simple "view source".)
I have a php script that is a bit of a mess and after a form entry, I need to get an address, and display it on a google map. The html and php is crammed into the same script so I essentially need to call the JavaScript as the PHP is happening. Is there a way to do this?
Thanks,
Alex
You can POST your from to a different frame (or iframe), so your page would not reload. The response of your PHP file which comes back to that frame can contain JavaScript code, which will be executed. Something like:
echo('<script type="text/javascript"> alert("Executed on client side"); </script>');
No, PHP executed by the server and returns the full response to the browser. JavaScript in the page is then executed by the client.
You can't call Javascript functions from PHP. You can set the Javascript to run when the page loads instead.
What you want is something like this:
<script type="text/javascript"></script>
var userAddress = "<?php echo $_POST['address']; ?>";
doSomethingWithAddress(userAddress);
</script>
If that code is on the page which you are POSTing the address to, it would take the address from the user, and write it into a javascript tag. The PHP will get executed first on the server, before building the HTML document. This new document has the variable available to the javascript.
I don't know how you would go about doing that, but this seems like a good place to start looking:
http://code.google.com/intl/en/
I want to post a whole page using ajax to php file to be parsed.
say the sources is `http://www.mysite.com/page-1.
now post this page (from <html> to </html>) to "parse-page.php". and retrieve it with $_POST['document'].
Considering you just want to post the data and ignore anything coming back from the php, this should work.
$.post("parse-page.php", {'document', $('body').html()});
For more info:
http://api.jquery.com/jQuery.post/
I'm thinking you can use javascript to store the innertext of the html tag and send that variable through ajax.
Here is the code:
$('#sousmenu a').click (function (){
startSlideshow(<?php echo json_encode(glob("photos-" .$_GET["folder"]. "/*.jpg"));?>);
return false;
});
The question is I like the HREF to change and get caught by PHP, now it doesn't do anything, but writing the ?folder=portraits works.
Here is the page.
**** Simpler *****
Maybe I am not clear, it happens sometimes!
I want the link href to be send to this PHP function,
<?php echo json_encode(glob("photos-" .(i what the href link). "/*.jpg"));?>
so clicking on the link animaux will send animaux to the glob() PHP function and will get all the .jpg files in the photos-animaux folder.
Clicking on the portraits will send the photo-portraits, etc.
If you want to modify the URL and have the added/changed variable picked by PHP interpreter you have to reload your page. Just altering the URL doesn't do anything because JS is executed after PHP processing.
If your site is on http://example.com and you wish a myparam with value test to be passed to PHP you should add something like this in your JS:
document.location = 'http://example.com?myparam=test';
This will reload your page adding a new param which can be accessed in PHP by simply using $_GET['myparam'] variable.
You may also want to consider using AJAX to dynamically changing the contents of your page without having to refresh the whole page, but that's a little bit more complicated.
Look at the source in your browser.
Php is server-side, and that means you need to use ajax or reload whole page to get a response.
There is a nice ajax part of tutorial on jquery website, after reading it you should be able to do what you want: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax