FAQ |
Kalender |
|
![]() |
#1 | ||
|
|||
Medlem
|
hejsan,
jag har en JS variabel som jag väldigt gärna skulle vilja uppdatera med AJAX. dock fungerar det inte, JS variabeln blir helt tom istället för att få texten jag tilldelar i variabeln. jag uppskattar all slags hjälp och vägledning. min ajax.js-fil Kod:
//ALL webbrowsers is supported function createRequestObject() { * *var ro; * *var browser = navigator.appName; * *if(browser == "Microsoft Internet Explorer"){ * * * *ro = new ActiveXObject("Microsoft.XMLHTTP"); * *}else{ * * * *ro = new XMLHttpRequest(); * *} * *return ro; } var http = createRequestObject(); //sending information function sendRequest(action) { * *http.open('get', 'rpc.php?action='+action); * *http.onreadystatechange = handleResponse; * *http.send(null); } //get information function handleResponse() { * *if(http.readyState == 4){ * * * *var response = http.responseText; * * * *var update = new Array(); * * * * * *scObj1.block[1]= response; * *} } Kod:
<?php if(isset($_REQUEST['action'])) { $randomNr = rand(0, 50); //check what is sent * switch($_REQUEST['action']) * { * * * * case 'foo': * * * // do something * * * echo "<script>scObj1.block[0]= \"here it comes $randomNr\"</script>"; * * * * * * break; } ?> Kod:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Isa - Ajax example</title> <script language=JavaScript src="ajax.js" type=text/javascript></SCRIPT> <script src="scroller.js.php" type=text/javascript></SCRIPT> </head> <body onLoad="scObj1.scroll();"> <a href="javascript:sendRequest('foo')">[foo]</a> * <div id="foo"> * *as *</div> * *live: <DIV id="sMain" ></DIV> </DIV> </body> </html> |
||
![]() |
![]() |
Svara |
|
|