60734
Goto Top

Ajax problem

Hallo,

ich versuche gerade verzweifelt mit folgendem Skript einen Ajax Request zu machen.
Ich möchte aber auf jeden Fall, dass die Funktion ajax() die Daten per return zurückgibt.
Leider ist mir das noch nicht gelungen!
Hier mal der Quellcode, vielleicht kann mir ja mal einer weiterhelfen.

Vielen Dnak schonmal!

 
<script>
var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  } catch (E) {
   xmlhttp=false;
  }
 }
@else
 xmlhttp=false
 @end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {  
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


function ajax(url)
{
xmlhttp.open("GET",url,true);  
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   return xmlhttp.responseText;
  }
 }
xmlhttp.send(null);
}

</script>

<input type=button onclick="alert(ajax('/test.txt'));">  

Content-Key: 103691

Url: https://administrator.de/contentid/103691

Ausgedruckt am: 28.03.2024 um 23:03 Uhr