SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Including .js after data request (ajax)

    I wrote a form with a little DOM/AJAX to submit the form data.
    The page is being used in google ad campaign, so after a user fills in the form, a google script is run to count conversions.

    I am having trouble getting the script to work properly. Since I am not reloading a page, I am including the file dynamically the DOM WAY. Below is a snippet of the code. The code is part of a function that runs when the readyState == 4.

    Code:
    var scriptNode = document.createElement('script');
    
    scriptNode.setAttribute('language', 'javascript');
    scriptNode.setAttribute('type', 'text/javascript');
    scriptNode.setAttribute('src', 'js/google.js');
    
    var googleConversion = document.createElement('script');
    googleConversion.setAttribute('language', 'javascript');
    googleConversion.setAttribute('type', 'text/javascript');
    googleConversion.setAttribute('src', 'http://www.googleadservices.com/pagead/conversion.js');
    
    var googleImg = document.createElement('img');
    googleImg.setAttribute('height', '1');
    googleImg.setAttribute('width', '1');
    googleImg.setAttribute('border', '0');
    googleImg.setAttribute('src', 'http://www.googleadservices.com/pagead/conversion/1065925913/?value=1&label=PURCHASE&script=0');
    I've tested it using an alert box in the google.js file and I do receive the alert box, but google doesn't seem to be tracking this code properly.

    Is this the correct way to import a file?
    Thanks for any help,
    Rich
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could that be because your not adding the newly created items to the body of the document?

    ie, document.getElementsByTagName("TBODY")[0].appendChild(googleImg);

    I take it your google.js has the above code in (where you are creating and setting the googleImg)


  3. #3
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gRoberts,

    I actually do append the element which I will paste that portion here as well.
    The google image is from google itself - it is genereated by adWords.

    This is the page I developed so you can see what I am working with. Because the page does not reload, I can't see the generated code.

    http://www.divvies.com/divvies.php?p...l&item=popcorn

    Code:
    statusImage.appendChild(procImage);
    	newWhite.appendChild(statusImage);
    	newWhite.appendChild(respText);
    	newWhite.appendChild(shopMoreLink);
    	newWhite.appendChild(scriptNode);
    	newWhite.appendChild(googleConversion);
    	bottomParent.replaceChild(newWhite, whiteArea);
    newWhite is a newly created Div to replace a div where the form was.
    This was my first AJAX related task, so if my approach was odd, that would be why.
    Thanks for any suggestions.
    Rich
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site


Bookmarks

Posting Permissions

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