AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi AJAX Content auslesen
Thema durchsuchen
Ansicht
Themen-Optionen

AJAX Content auslesen

Ein Thema von lowF · begonnen am 26. Feb 2009 · letzter Beitrag vom 27. Feb 2009
Antwort Antwort
lowF

Registriert seit: 18. Dez 2008
37 Beiträge
 
#1

Re: AJAX Content auslesen

  Alt 26. Feb 2009, 21:27
Okay hier mal der gesamte Quellcode.

Delphi-Quellcode:
//create request object called httprequest
function createAjaxObj() {
  var httprequest = false;
  if (window.XMLHttpRequest) { // if Mozilla, Safari etc
    httprequest = new XMLHttpRequest();
    if (httprequest.overrideMimeType) httprequest.overrideMimeType('text/xml');
  }

  else if (window.ActiveXObject) { // if IE
    try {
      httprequest = new ActiveXObject("Msxml2.XMLHTTP");
    }
 
    catch (e){
      try{
        httprequest = new ActiveXObject("Microsoft.XMLHTTP");
      }

      catch (e){}
    }
  }
  return httprequest;
}

//http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm
//ACCESSIBLE VARIABLES (for use within your callback functions):
//1) ajaxpack.ajaxobj //points to the current ajax object
//2) ajaxpack.filetype //The expected file type of the external file ("txt" or "xml")
//3) ajaxpack.basedomain //The root domain executing this ajax script, taking into account the possible "www" prefix.
//4) ajaxpack.addrandomnumber //Set to 0 or 1. When set to 1, a random number will be added to the end of the query string of GET requests to bust file caching of the external file in IE. See docs for more info.

//ACCESSIBLE FUNCTIONS:
//1) ajaxpack.getAjaxRequest(url, parameters, callbackfunc, filetype)
//2) ajaxpack.postAjaxRequest(url, parameters, callbackfunc, filetype)


var ajaxpack = new Object()
ajaxpack.basedomain = "http://"+window.location.hostname
ajaxpack.ajaxobj = createAjaxObj()
ajaxpack.filetype = "txt"
ajaxpack.addrandomnumber = 0 //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest = function(txt1, parameters, callbackfunc, filetype) {
  ajaxpack.ajaxobj = createAjaxObj() //recreate ajax object to defeat cache problem in IE
  if(ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
  var parameters=parameters+"&ajaxcachebust="+new Date().getTime();
  if(this.ajaxobj) {
    this.filetype = filetype;
    this.ajaxobj.onreadystatechange = callbackfunc;
    this.ajaxobj.open('GET', txt1+"?"+parameters, true);
    this.ajaxobj.send(null);
  }

}

ajaxpack.postAjaxRequest=function(txt1, parameters, callbackfunc, filetype) {
  ajaxpack.ajaxobj = createAjaxObj() //recreate ajax object to defeat cache problem in IE
  if(this.ajaxobj) {
    this.filetype = filetype;
    this.ajaxobj.onreadystatechange = callbackfunc;
    this.ajaxobj.open('POST', txt1, true);
    this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    this.ajaxobj.setRequestHeader("Content-length", parameters.length);
    this.ajaxobj.setRequestHeader("Connection", "close");
    this.ajaxobj.send(parameters);
  }

}

function processGetPost(){
  var myajax = ajaxpack.ajaxobj;
  var myfiletype = ajaxpack.filetype;
  if(download_loading_count > 41) {}

  else {
    if (myajax.readyState == 4){ //if request of file completed
      if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
        if (myfiletype=="txt") {
          document.getElementById('download_details').style.display = 'block';
          hideDownloadsLoading();
          document.getElementById('download_details').innerHTML = myajax.responseText;
        }

        else {
          alert(myajax.responseXML);
        }

      }
    }
  }
}

function createpoststring() {
    var url_value = document.getElementById("chooser_form").txt1.value;
    var poststr = "url=" + escape(url_value);
  return poststr;
}


var download_loading_int = false;
var download_loading_count = 0;
var selected_form = 0;
var history_value = '';

//main function
function openDownloads() {
  url_value = document.chooser_form.txt1.value;
  if(url_value == "")
    {alert('Please enter a URL first.');document.forms[selected_form_name].txt1.focus();}

  else {
document.getElementById('download_container').style.display = 'block';
document.getElementById('download_details').style.display = 'none';
document.getElementById('download_loading').style.display = 'inline';
document.getElementById('download_loading_c').innerHTML = '';
    if(download_loading_int) {
      clearInterval(download_loading_int);
    }

    download_loading_count = 0;
    
   ajaxpack.postAjaxRequest("index_p/", createpoststring(), processGetPost, "txt");
    download_loading_int = setInterval('if(download_loading_count == 40){hideDownloadsLoading();document.getElementById(\'download_details\').style.display = \'block\';document.getElementById(\'download_details\').innerHTML = \'Error: Timeout. Please try again.\';}download_loading_count++;document.getElementById(\'download_loading_c\').innerHTML += "."', 2000);

  }
}

function hideDownloadsLoading() {
  if(download_loading_int) {
    clearInterval(download_loading_int);
  }

  document.getElementById('download_loading').style.display = 'none';
}

function htmlspecialchars(str){
    return str.replace(/&/g, "&").replace(/</g,"<").replace(/>/g, ">").replace(/'/g, "'").replace(/"/g, """);
}
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:46 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz