[AJAX] Nakładka na XMLHttpRequest |
[AJAX] Nakładka na XMLHttpRequest |
27.06.2009 - 17:24
Post
#1
|
|
![]() Bywalec ![]() ![]() ![]() Grupa: Użytkownik Postów: 113 Dołączył: 14.04.2009 Skąd: Wodzisław Użytkownik nr: 437 |
Hej!
Kupiłem niedawno książkę Ajax i java script Tworzenie i optymalizacja aplikacji sieciowych (helion.pl). I jeden z przyładów nie chce mi działac :/ Działa dopiero za drugim kliknięciem na link :/ Pomocy bo już męczę się z tym drugi dzień :/ HttpClient: KOD function HttpClient () {} HttpClient.prototype = { requestType:'POST', isAsync:true, rXmlHttp:false, callback:false, onSend:function () { document.getElementById('httpClientStatus').style.display = 'block'; }, onLoad:function () { document.getElementById('HttpClientStatus').style.display = 'none'; }, onError:function (error) { alert(error); }, init:function () { try { this.rXmlHttp = new XMLHttpRequest(); } catch (e) { var aXmlHttp = new Array('MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'); var bSuccess = false; for (var i=0;i<aXmlHttp.lenght && !bSuccess;i++) { try { this.rXmlHttp = new ActiveXObject(aXmlHttp[i]); bSuccess = true; } catch (e) {} } if (!bSuccess) { this.onError('Zadanie nie powiodlo sie'); } } }, makeRequest:function (url,payload) { if(!this.rXmlHttp) { this.init(); } this.rXmlHttp.onReadyStateChange = this.readyStateChangeCallback(); this.rXmlHttp.open(this.requestType,url,this.isAsync); this.rXmlHttp.send(payload); if (!this.isAsync) { return this.rXmlHttp.responseText; } else return null; }, readyStateChangeCallback:function () { switch(this.rXmlHttp.readyState) { case 2 : this.onSend(); break; case 4 : this.onLoad(); document.write('statechange'); if (this.rXmlHttp.status == 200) this.callback(this.rXmlHttp.responseText); else this.onError('Blad!'); break; } } } index.html KOD <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="HttpClient.js"></script> </head> <body> <script type="text/javascript"> var client = new HttpClient(); client.isAsync = true; function test() { client.callback = function (result) { document.write('YEAH it works'); document.write(result); } client.makeRequest('php.php', 'null'); } </script> <div id="HttpClientStatus" style="display:none">Wczytywanie...</div> <a href='java script:test()'>bee</a> <div id="target"></div> </body> </html> php.php KOD echo "aasadasd"; Proszę o pomoc i pozdrawiam PS:Sorrka za document.writy ale łatwiej się połapać co działa ;-) -------------------- Pozdrowienia, Qwak.
|
|
|
|
![]() ![]() |
| Wersja Lo-Fi | Aktualny czas: 17.05.2012 - 03:51 |