最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Run a PHP function on document ready? - Stack Overflow

programmeradmin0浏览0评论

Is there anyway for me to run a certain php function when the document loads pletely? I am trying to run a function which will mark a notification as read only when the document has been loaded pletely. What can I do?

Is there anyway for me to run a certain php function when the document loads pletely? I am trying to run a function which will mark a notification as read only when the document has been loaded pletely. What can I do?

Share Improve this question asked Oct 6, 2013 at 12:51 christianleroychristianleroy 1,1045 gold badges25 silver badges39 bronze badges 1
  • Reconsider your logic or just use ajax or load an IMG in JS onLoad. PHP is long finished building your page's HTML when your document ready gets triggered. You need to callback to achieve the result you seek. – CodeAngry Commented Oct 6, 2013 at 12:56
Add a ment  | 

3 Answers 3

Reset to default 7

You can detect the "document-ready" event with a Javascript script and when that is triggered, perform an AJAX request to a PHP page that will run the script you need.

With jQuery it gets as simple as using ready() and ajax().

yes you can do an ajax call to that php file on document ready.

You must use AJAX for this, php is done server side so AJAX is the only way :)

发布评论

评论列表(0)

  1. 暂无评论