Skip to content Skip to sidebar Skip to footer

How To Get, In Php, The Entire Html Of A Page Loaded In Part From Jquery

i've this problem for days... I have to load from php the entire html of a page. On this page there is a jquery function that is called when all the page is loaded. This function l

Solution 1:

The problem is that you are trying to mix server and client.

PHP runs on the server Javascript (and therefor also jQuery) runs in the client browser.

There's no easy way to run the javascript using PHP. As far as I know, it's not even possible. Other languages, such as Java might be able to do what you are trying to do.

You should look at another way to do this.

This is also the reason why webcrawlers never gets affected by stuff you do using javascript. This is a nice thing to keep in mind when developing. Your dynamic loading will not be indexed by these crawlers at all.

Solution 2:

As far as I know, this is not possible "with only PHP". Javascript runs on the client instead of the server and therefore it would not be possible without some sort of a browser emulator environment.

Edit: You could put javascript in the web page itself which would fetch the innerHTML of the whole web page after it was fully generated and then use an ajax call to send that to your server. You would have to stay within the limitations of the same-origin-policy (which doesn't allow you to make ajax calls to domains other than where the host web page came from).

Solution 3:

Like the others have said, jquery is javascript, and is typically executed by the client (web browser) rather than the server.

PHP, being a server-side language, has no javascript interpreter.

The easiest way that I know of to run javascript using PHP is via web-testing tools, which often integrate a headless browser. You could check out mink, which has a back-end for the zombie node.js headless browser.

There's also the phantomjs headless browser with various PHP interfaces like this one, which I found with a quick google search.

In the more resource-intensive arena, there's also selenium, which has PHP interfaces as well.

Post a Comment for "How To Get, In Php, The Entire Html Of A Page Loaded In Part From Jquery"