Run the php script on the ready Jquery document

I would like to know if is there a way to load a part of script only when the document is ready, i mean when all css, js, and images are downloaded Run the php script that is a bit heavy.

in php i know that can be use an if else but on jquery ?

can be: ?

        jQuery( document ).ready(function( $ ) {

getChildHtml('header'); ?>
getChildHtml('top_callout'); ?>
getChildHtml('breadcrumbs'); ?>
getChildHtml('global_messages'); ?> on document ready call content getChildHtml('content'); ?>
getChildHtml('footer'); ?> getChildHtml('before_body_end'); ?>

Any help is appreciated !

I think there is a language confusion. PHP is a

language. It has already run and completed by the time the raw source touches your browser. JavaScript on the other hand is

parsed and rendered in the browser.

If you need to run a PHP script after a page loads, you’ll need to make use of AJAX. You’ll have to do something like the following:

$(window).load(function () {
        url: "some-php-script.php",
        data: { ... } // data to send to php if applicable,
        ... // other options that may be needed
        success: function (res) {
            ... // handle successful return of data (if applicable)
        error: function (res) {
            ... // handle error if appropriate



Suggested by user3553931

Since you’re wanting to wait for all stylesheets, scripts and images to load, I’ve updated my answer to use the load
event instead of DOMContentLoaded
(the event behind $(document).ready

Per the MDN documentation below, it seems that the load
event will fulfill your question requirements better than the DOMContentLoaded



The DOMContentLoaded event is fired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading (the load event can be used to detect a fully-loaded page).
Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Run the php script on the ready Jquery document

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录