Jump to content

Urgent Help please - jQuery DIV refresh of DIV with .js file not working


Forex-Coder

Recommended Posts

Hi,

 

I am using jQuery and the code found in the link below to refresh a div.

 

http://www.phpfreaks.com/forums/index.php?topic=243527.0

 

However, I am running into a wall. The div I need to refresh is displaying a .js file. When the DIV is reloaded it refreshes forward into a new page with just the contents of the .js file.

 

Any ideas on how to get the DIV to refresh yet remain on the same page.

 

Here is some of what is in the.js file

 

//This function calculates the difference between two dates/times. It returns an array with 2 items
//  containing the hours and the minutes
function difference(later, current)
{
var return_array = new Array(2);

var diff = (Date.parse(later) - Date.parse(current)) / 1000; //number of seconds between the current date and the target date

return_array[0] = Math.floor((diff / 3600),0);				 //number of hours
diff = diff - (return_array[0]*3600);
return_array[1] = Math.floor((diff / 60),0);				 //number of minutes

return return_array;
}


//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//

//This function return the adjustment for Daylight Saving Time in Wellington, New Zealand
function new_zealand_DST()
{
var today = new Date();
var DSTdateLow = new Date();
var DSTdateHigh = new Date();

DSTdateLow.setUTCSeconds(0);
DSTdateLow.setUTCMinutes(0);
DSTdateLow.setUTCHours(14);			//Wellington time is GMT+13 before DST expires at 3am local time. 
DSTdateLow.setUTCDate(4);			//Because when DST expires in New Zealand it's still the previous day GMT-time, the date that is passed here must be the previous day 
DSTdateLow.setUTCMonth(3);			//Since Javascript starts counting the months at 0, April = 3
DSTdateLow.setUTCFullYear(2009);

DSTdateHigh.setUTCSeconds(0);
DSTdateHigh.setUTCMinutes(0);
DSTdateHigh.setUTCHours(15);		//Wellington time is GMT+12 before DST comes in effect at 3am local time. 
DSTdateHigh.setUTCDate(26);			//Because when DST comes in effect in New Zealand it's still the previous day GMT-time, the date that is passed here must be the previous day 
DSTdateHigh.setUTCMonth(;			//Since Javascript starts counting the months at 0, September = 8 
DSTdateHigh.setUTCFullYear(2009);

//If the date and time right now is higher than the low date and lower than the high date, DST does NOT apply and
//  it's GMT+12 hours, else it's GMT+13 hours (New Zealand being in the Southern Hemisphere is the opposite of the
//  Northern Hemisphere with the timing of DST)
if ((today >= DSTdateLow) && (today < DSTdateHigh)) {
	return 12; }
else {
	return 13; }
}

//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//
//This is the main execution of the script


var ret_array = new Array(2)

var d = new Date();						//This variable is used to hold the current time
var laterDate = new Date();				//This variable gets modified during execution to hold a future time, either the upcoming opening or closing of the market


var GMThour = d.getUTCHours();			//This variable holds the current hour, adjusted to GMT time 
var GMTmins = d.getUTCMinutes();		//This variable holds the current minutes, adjusted to GMT time (won't change from the local time, but it's more to keep the variables similar later) 
var GMTsecs = d.getUTCSeconds();		//This variable holds the current seconds, adjusted to GMT time (won't change from the local time, but it's more to keep the variables similar later) 
var GMTday = d.getUTCDay();				//This variable holds the current day of the week, adjusted to GMT time 
var GMTdate = d.getUTCDate();			//This variable holds the current day of the month, adjusted to GMT time 

var DSThourClose = 0;					//This variable will hold the market's closing time, adjusted for the local Daylight Saving Time settings, if it applies 
var DSThourOpen = 0;					//This variable will hold the market's opening time, adjusted for the local Daylight Saving Time settings, if it applies 

document.write("<div style='float: left;'><div style='width: 600px;'>");
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//


//FOREX market is open from 21:00 GMT Sunday until the New York closing, which can be 21:00 GMT (DST in New York) or 22:00 (non-DST) 

DSThourOpen = 8 - new_york_DST();
DSThourClose = DSThourOpen + 9;						//closing time GMT on Friday when New York closes 

DSThourOpen = 21;									//opening time is 21:00 GMT on Sundays 


//MARKET IS CLOSED [saturdays, Fridays after the New York close, Sundays before 21:00 GMT]
if ((GMTday == 6) || ((GMTday == 5) && (GMThour >= DSThourClose)) || ((GMTday == 0) && (GMThour < DSThourOpen)))
{
  laterDate = setUTC(DSThourOpen,0,(GMTdate + ((7-GMTday)%7)));		//the opening day and time of the market
  document.write("<div style='background-image:url(http://www.forex4newbs.com/forex-tools/clock/images/fx-close.png); width:590px; height:35px; padding: 15px 0 0 10px;'><b style='font: 15px Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color:#333333'>The Forex market opens in ");
}

else   //MARKET IS OPEN 
{
  laterDate = setUTC(DSThourClose,0,(GMTdate + (5-GMTday)));		//the closing day and time of the market
  document.write("<div style='background-image:url(http://www.forex4newbs.com/forex-tools/clock/images/fx-open.png); width:590px; height:35px; padding: 15px 0 0 10px;'><b style='font: 11px Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color:#333333'>The Forex market closes in ");
}

ret_array = difference(laterDate, d);

document.write(ret_array[0] + "hrs " + ret_array[1] + "min</b>");

document.write("</div><br clear='all'>");
document.write("<div style='float:left; width 290px; margin: 0 20px 0 0;'>");
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//


//-------------------------------------------------------------------
//The New York session is open daily from 8am until 5pm, local time |
//-------------------------------------------------------------------

DSThourOpen = 8 - new_york_DST();			//New York's opening time converted to GMT time 
DSThourClose = DSThourOpen + 9;  			//New York closes 9 hours after opening


//NEW YORK IS CLOSED [saturdays, Sundays, weekdays after 21:00 GMT (DST)/22:00 GMT (non-DST), weekdays before 12:00 GMT (DST)/13:00 GMT (non-DST)]
if ((GMTday == 6) || (GMTday == 0) || (GMThour >= DSThourClose) || (GMThour < DSThourOpen))
{
  laterDate = setUTC(DSThourOpen,0,GMTdate);	//laterDate is the upcoming opening time, GMTdate might be updated below 

  switch (GMTday)
  {
  case 0: laterDate.setUTCDate(GMTdate + 1);			//New York is closed all day Sunday GMT time, add 1 day for the next opened day to be Monday 
  		  break;
  case 6: laterDate.setUTCDate(GMTdate + 2);			//New York is closed all day Saturday GMT time, add 2 days for the next opened day to be Monday 
  		  break;
  case 5: if (GMThour >= DSThourClose) laterDate.setUTCDate(GMTdate + 3);  //If it's Friday after closing, then the next business day is Monday, 3 days later 
  		  break;
  default: if (GMThour >= DSThourClose) laterDate.setUTCDate(GMTdate + 1);  //If it's a regular business day after closing but before midnight, the next opened day is the next day
  } 
  document.write("<div style='background-image:url(http://www.forex4newbs.com/forex-tools/clock/images/us-close.png); width:290px; height:90px; margin: 0 0 10px 0;'>");
  document.write("<div style='width:175px; height:80px; margin: 0 0 0 100px; padding: 10px  15px 0 0'><b style='font: 11px Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color:#333333'>U.S. market opens in<br><br></b><b style='font: 18px Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color:#333333; text-align:center;'>");
}

else
//NEW YORK IS OPEN 
{
  laterDate = setUTC(DSThourClose,0,GMTdate);	//laterDate is the upcoming closing time. For New York, the day GMT won't change 
  document.write("<div style='background-image:url(http://www.forex4newbs.com/forex-tools/clock/images/us-open.png); width:290px; height:90px; margin: 0 0 10px 0;'>");
  document.write("<div style='width:190px; height:90px; margin: 0 0 0 100px; padding: 10px  15px 0 0'><b style='font: 11px Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color:#333333'>U.S. market closes in<br><br></b><b style='font: 18px Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color:#333333; text-align:center;'>")
}

ret_array = difference(laterDate, d);			//calculate the difference between now and the upcoming event, whether it's closing time or opening time 
document.write(ret_array[0] + "hrs " + ret_array[1] + "min</b></div></div>");


//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+//

document.write("</div><br clear='all'></div></div>");

I don't understand what is wrong? Instead of it running the JS code it's displaying it? The jQuery load() function will parse it as HTML. In the file you are loading, try putting <script></script> tags around the JS code

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.