Run the php script on the ready Jquery document

综合技术 2018-02-16 阅读原文

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!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!


Best Books For Learning Web Development: The Ultim... Learning to code websites is a tough but rewarding goal. There’s a lot to learn ...
Assign sounds to element with drag drop I have a interesting idea(debatable). Basically I would like to make a ...
Sylius 1.1.5 和 1.0.14 发布,PHP 电子商务网站框架... Sylius 1.1.5 和 1.0.14 发布了。Sylius是第一个基于Symfony和Doctrine定制解决方案的电子商务框架。高质量的代码,强大的测试...
Convert a php to a csv string I have several method to transform php array to csv string both from stackove...
Juniors Literally Can’t Write Switch Stateme... If you follow the PHP community on Twitter and other places you'll have noticed...