Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-02-2006, 04:37 PM   PM User | #1
ton
New to the CF scene

 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ton is an unknown quantity at this point
Question Modifiying script to support two variables

I would've thought it would be easy, but either there's something I'm missing, or I've been mentally challenged for the past hour.

I have a script that loads an external banner ad page into my main page via ajax. The way the script is setup, you call it from body onload of the main page and the variable for the ad page's location is already set inside the script, so it just places the page/ad in the chosen div'd location.

The onload call is:
Code:
ajax(page,'topads');
The script I am using currently is:
Code:
var page = "ads/topads.php";
function ajax(url,target) {
    // native XMLHttpRequest object
   document.getElementById(target).innerHTML = 'Loading New Banner Ad...';
   if (window.XMLHttpRequest) {
       req = new XMLHttpRequest();
       req.onreadystatechange = function() {ajaxDone(target);};
       req.open("GET", url+"?bustcache="+new Date().getTime(), true);
       req.send(null);
   // IE/Windows ActiveX version
   } else if (window.ActiveXObject) {
       req = new ActiveXObject("Microsoft.XMLHTTP");
       if (req) {
           req.onreadystatechange = function() {ajaxDone(target);};
           req.open("GET", url+"?bustcache="+new Date().getTime(), true);
           req.send();
       }
   }
		   setTimeout("ajax(page,'topads')", 30000);
}
function ajaxDone(target) {
   // only if req is "loaded"
   if (req.readyState == 4) {
       // only if "OK"
       if (req.status == 200 || req.status == 304) {
           results = req.responseText;
           document.getElementById(target).innerHTML = results;
       } else {
           document.getElementById(target).innerHTML="ajax error:\n" +               req.statusText;
       }
   }
}
What I need is to make the location of the page it grabs set when I call it. Reason being is because I have two sets of ads on my main page that I want to handle like this. So basically, I want to be able to set all the options in the onload call so it would look like this:
Code:
ajax('ads/topads.php','topads');
Sorry if this sounds dumb, I know it does to me, and I feel dumb for not even being able to figure it out when I am usually great with javascript. Thanks in advance for any help you can give!
ton is offline   Reply With Quote
Old 08-03-2006, 07:06 PM   PM User | #2
ton
New to the CF scene

 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
ton is an unknown quantity at this point
^^bump^^

...can no one lend a hand or even help walk me through it? can't be that difficult...
ton is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:33 PM.


Advertisement
Log in to turn off these ads.