Ajax in Unterfenstern
-
Hi,
ich habe ein Problem mit Ajax, bzw. mit der Prototype Ajax.Request Klasse um solche Funktionen zu nutzen.
Requests klappen super toll - wenn der gleiche Code jedoch in einem Popup/Unterfenster ausgeführt wird, meckert der Javascript Interpreter über fehlende Prototype Funktionen.Folgend ist der Code, einfach in ne neue HTML kopieren und fertig.
Was kann man beobachten: Der Klick auf "doAjax" macht erfolgreich einen XMLRPC Request. Nachdem man ein neues mit dem "document.open" Button geöffnet hat, funktionieren in dem neuen Fenster keine doAjax() Aufrufe mehr. Der in der Javascript Konsole des Firefoxes angezeigte Fehler lautet: "Object.extend is not a function" , der nachfolgende Stacktrace ist immer unterschiedlich.Danke für Hilfe
Die Prototype.js gibts hier: http://prototype.conio.net/dist/prototype-1.4.0.js
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de"> <head> <title>title</title> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript"> Event.observe(window, 'load', function(event) { doAjax (); }); function doAjax() { // AJAX Request ausfuehren new Ajax.Request('/foo/bar', { onException: function(e) { alert("exc: " + e); }, onSuccess: function(t) { alert("succ:" + t); }, onFailure: function(t) { alert("fail: "+t); } }); return false; } </script> </head> <b> Ajax Demo </b> Click 'doAjax' to trigger a Ajax request. Note the messagebox triggered by the 'onException' even of Ajax.Request in doAjax()<br/> <br/> Click 'window.open' to open a new popup window.<br/> Inside this window Ajax.Request does not work anymore (no xmlrpc request). <br/> There is one Javascript error though: <br/> <br/> * <b>Object.extend is not a function</b><br/> prototype.js (line 604)<br/> prototype.js (line 549)<br/> prototype.js (line 83)<br/> prototype.js (line 550)<br/> prototype.js (line 624)<br/> prototype.js (line 20)<br/> doAjax-chat_room.html (line 22)<br/> onclick-chat_room.html (line 1)<br/> anonymous-chat_room.html (line 20)<br/> prototype.js (line 738)<br/> prototype.js (line 654)<br/> prototype.js (line 626)<br/> prototype.js (line 20)<br/> doAjax-chat_room.html (line 22)<br/> onclick<br/> <form action="foo"> <input type="button" onclick="return doAjax();" value="doAjax()"/> <input type="button" onclick="window.open('chat_room.html', 'titel', 'width=640,height=480,scrollbars=no,status=no,toolbar=no,menubar=no')" value="window.open()"/> </form> </body> </html>
-
Lösung gefunden.
Der Firefox lädt die JS Datei nicht neu bei einem neuen Fenster, Objekte die in einer JS erzeugt werden sind dieser jedoch zugeordnet, so dass beim erneuten Aufruf von Initialisierungsfunktionen (in einem neuen Fenster) eigentlich als null erwartete Objekte schon erzeugt sind. Doof. "?<random_number>" an die JS angehangen löst der Problem. JippieTrotzdem danke fürs lesen!