Log in

View Full Version : How to replace PHP Include function with a javascript call



wilm1998
04-20-2009, 07:24 PM
On my web site (http://thebestplacesinsandiego.com), I include weather information pulled from National Weather Service XML files.

The xml data is parsed and organized in a php5 file.

I use <?php include("filename"); ?> to pull the weather information from the php5 file into my web site.

Unfortunately, the xml data from the NWS can be slow to load. On occasion, it does not load at all. When it does not load, the user can no longer click through to another page. Basically, the page hangs up on the user.

I am hoping javascript can solve this problem. My thought is, if I pull in the weather data from the php5 file to the web site using javascript, the browser will not hang up on the user in the event the weather data is not available.

I found information here http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_include/ that might be the answer to how I accomplish this. However, I have not figured out how to implement it correctly.

I've created a test page: http://shopwithtrust.com/weather.php
The top of the page pulls in the data directly from php5 using the PHP Include.
The bottom of the page is my attempt to use the javascript to pull in the data.

Any suggestions on how I can provide visitors to my web site with smooth navigation in the event the weather information is not available would be greatly appreciated.