hoho Posted January 22, 2008 Report Share Posted January 22, 2008 Sveiki Meginu saakt apguut Ajax pamatus un saaku ar elementaaru piemeeru: HTMl skripts: <html> <head> <script src="selectcd.js"></script> </head><body><form> Select a CD: <select name="cds" onchange="showCD(this.value)"> <option value="Bob Dylan">Bob Dylan</option> <option value="Bee Gees">Bee Gees</option> <option value="Cat Stevens">Cat Stevens</option> </select> </form><p> <div id="txtHint"><b>CD info will be listed here.</b></div> </p></body> </html> Un JS: var xmlHttp function showCD(str) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="index.php" url=url+"?q="+str url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("txtHint").innerHTML=xmlHttp.responseText } } function GetXmlHttpObject() { var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } Bet kad es kaut ko izveelos dropdownaa paraadas veel viena rindinja un veel viens dropdows ... kaapeec taa? :( Link to comment Share on other sites More sharing options...
andrisp Posted January 22, 2008 Report Share Posted January 22, 2008 Pirmkārtāt, sāc ar to, ka izmanto šeit code tagu vai arī ieliec kodu paste.php.lv. Link to comment Share on other sites More sharing options...
Delfins Posted January 22, 2008 Report Share Posted January 22, 2008 Nav jēgas ķertires klāt AJAX, ja nesaprot pamatus. Atver lapu ar linku, kas šeit rodās un viss taps skaidrs. var url="index.php" url=url+"?q="+str url=url+"&sid="+Math.random() Link to comment Share on other sites More sharing options...
hoho Posted January 22, 2008 Author Report Share Posted January 22, 2008 HTML kods: http://paste.php.lv/6773 un selectcd.js: http://paste.php.lv/6774 Link to comment Share on other sites More sharing options...
hoho Posted January 22, 2008 Author Report Share Posted January 22, 2008 nu labi, kas ir var url="index.php" url=url+"?q="+str url=url+"&sid="+Math.random() es saprotu, taa ir taa lapa ar GET parametriem. bet kaa uztaisiit lai peec darbiibas ar dropdownu rindinja neatkartotos?! :( Link to comment Share on other sites More sharing options...
andrisp Posted January 22, 2008 Report Share Posted January 22, 2008 (edited) Ar JS tev izskatās, ka viss ok. Kā jau Delfins teica - paskaties, ko atgriež tas index.php fails, kad tam padod parametrus. bet kaa uztaisiit lai peec darbiibas ar dropdownu rindinja neatkartotos?! :( Kā tas ir ? Tev tur ar JS tas dropdown vispār netiek aiztikts. Tur nekas nevar atkārtoties. Ja tu to domāji tā, ka pārlūks rāda izvēlēto vienību gan pašā augšā, gan arī sarakstā, tad to to mainīt nevari. Ja nu veidojot pats savu dropdown menu, izmantojot HTML un JS. Edited January 22, 2008 by andrisp Link to comment Share on other sites More sharing options...
Delfins Posted January 22, 2008 Report Share Posted January 22, 2008 da viņš to pašu kontentu ieliek divā... `Ifreims-Ifreimā` mūžīgajā ciklā Link to comment Share on other sites More sharing options...
andrisp Posted January 22, 2008 Report Share Posted January 22, 2008 Delfins, kā tu zini ? Link to comment Share on other sites More sharing options...
Delfins Posted January 22, 2008 Report Share Posted January 22, 2008 Mana kristāla bumba rāda, ka AJAX izsauc to pašu URL-u, no kurienes tas tiek izsaukts Ko apstiprina šis: un veel viens dropdows (reāli tas pats HTML-s) Link to comment Share on other sites More sharing options...
hoho Posted January 22, 2008 Author Report Share Posted January 22, 2008 Jaa, taa arii bija :) Paldies, tagad sapratu .... :) Link to comment Share on other sites More sharing options...
Recommended Posts