topical media & game development

talk show tell print

mashup-amazon-09-09-01-MovieMogul-js-request.js / js



  // JScript File
  var myRequest;
  
  function Lookup(ItemId){
          GetData("api=amazon&operation=ItemLookup&ItemId=" + ItemId);
  }
  
  function DirectorSearch(keywords){
          GetData("api=amazon&operation=ItemSearch&Director=" + keywords + "&SearchIndex=DVD");
  }
  
  function YouTube(keywords){
          GetData("api=youtube&tag=" + keywords );
  }
  
  function ActorSearch(keywords){
          GetData("api=amazon&operation=ItemSearch&Actor=" + keywords + "&SearchIndex=DVD");
  }
  
  function GetData(myOperation) {
  
          myUrl="getdata.aspx?" + myOperation;
          
          // Is this a Microsoft browser?
          if (window.ActiveXObject) {
              // Create a new request
          myRequest = new ActiveXObject("Microsoft.XMLHTTP");
          if (myRequest) {
              myRequest.onreadystatechange = HandleResponse;
              myRequest.open("GET", myUrl, true);
              myRequest.send();
          }  
      } else if (window.XMLHttpRequest) {
          // If this is Firefox or Safari...        
          myRequest = new XMLHttpRequest();
          myRequest.onreadystatechange = HandleResponse;
          myRequest.open("GET", myUrl, true);
          myRequest.send(null);             
      } 
  }
  
  function HandleResponse() {
  
      // Find the results div
      var myDiv = document.getElementById('results');
      
      // Readystate 4 means we're done
      if (myRequest.readyState == 4) {
      
          // If the server returned OK
          if (myRequest.status == 200) {         
              var tmpDiv = document.createElement('div');
              tmpDiv.innerHTML = myRequest.responseText;
              myDiv.appendChild(tmpDiv);
              
          } else {
              myDiv.innerHTML = "Oops there was a problem, " + myRequest.statusText;
              myDiv.innerHTML = "<br/>Try again later";
          }
      }
  }
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.