Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    ton
    ton is offline
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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!

  • #2
    ton
    ton is offline
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ^^bump^^

    ...can no one lend a hand or even help walk me through it? can't be that difficult...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •