Problem with XMLHttpRequest

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MichaelHe
    New Member
    • Feb 2008
    • 1

    Problem with XMLHttpRequest

    Hi

    I'm having a bit starting problem with java ajax.

    I have this rather simple script
    Code:
    function UpdateSQL(ReleaseID, MediaTypeID, sideElement) {
        if (typeof XMLHttpRequest != 'undefined') {
            return new XMLHttpRequest();
        }
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
        return false; 
        
         req.onreadystatechange = function() {answerUpdateSQL(sideElement);};
         req.open("GET", "Submit2-addmedia.php" + "?ReleaseID=" + ReleaseID + "&MediaTypeID=" + MediaTypeID", true);
         req.send(null);
    }
         
    
    function answerUpdateSQL(sideElement) {
       var output = '';
       if(req.readyState == 4) {
          if(req.status == 200) {
             output = req.responseText;
             document.getElementById(sideElement).innerHTML = output;
             }
          }
      }
    And on the page I write
    [HTML]<img src="Graphics/Tree/cd.gif" onClick="Update SQL('1','4,'sho w');">
    <div id="show"></div>[/HTML]


    This should get the Submit2-addmedia.php file with the extensions ReleaseID = 1 and MediaTypeID = 4 but it just doesn't work.

    Nothing happens when I click the image.

    I have tried removing the extensions so the script is just
    req.open("GET", "Submit2-addmedia.php", true);
    and in the file just write "Test"
    But Test is not written in the show div.


    So something is wrong so it doesn't get the fle probably.
    But I'm new at this, and I just can't figure it out ?


    So can anyone tell me what I'm doing wrong.
    It's probably a simple little thing I'm missing ??


    Best
    Michael
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Moving from Java to JavaScript forum, since Java is not JavaScript.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      UpdateSQL('1',' 4,'show'); should be UpdateSQL('1',' 4','show'); Note the missing end single quote.

      Comment

      Working...