AJAX A,N,R,I 29 სექტ 2013, 22:23 AJAX ishifreba rogorc Asynchronous JavaScript And XML. saxelidan gamomdinare albat ukve mixvdit, rom es gankerdzoebuli programirebis ena araa, AJAX aris ubralod metodi, romelic iyenebs ukve arsebul standartebs, rezultatad ki gvadzlevs ufro swraf, da momxmareblistvis mosaxerxebel programebs. xazgasmit minda avghnishno, rom AJAX dafudznebulia JavaScript-sa da HTTP Request-ebze. aqedan gamomdinare sanam am dokumentaciis garchevas gaagrdzelebdit, dafiqrdit, xom ar jobs jer calke JavaScript-isa da raime serveruli mxaris programirebis enis garcheva. mat gareshe azri ara aqvs am dokumentaciis swavlis gagrdzelebas. swavlas vagrdzelebt imis gatvaliswinebit rom ase-tu-ise gesmit JavaScript-i, kargad gesmit HTML/XHTML da ra tqma unda icit serveruli mxaris programireba (PHP, ASP, ASPX, JSP an msgavsi). --------------- A,N,R,I 29 სექტ 2013, 22:23 AJAX-shi JavaScript-is XMLHttpRequest obieqti sashualebas gadzlevt daukavshirdet tqvens serverze gantavsebul skripts da monacemebi gacvalot mastan gverdis ganaxlebis gareshe. es yvelaferi xdeba sinqronuli HTTP translaciit brauzersa da veb- servers shoris. es nishnavs, rom JavaScript-is XMLHttpRequest obieqti (AJAX) chadgmuli unda qondes tqvens brauzers (yvela cnobil brauzers es obieqti moyveba) da ara dayenebuli iyos tqvens serverze. AJAX-is xmarebas sxvadasxva brauzerebshi mogvianebit gavarchevt, exla ki mtavaria gavigot is, rom es obieqti asrulebs shuamavlis rols tqvens brauzersa da servers shoris. --------------- A,N,R,I 29 სექტ 2013, 22:27 ra aris Http Request? rogorc ukve avghnishnet, AJAX tavidan bolomde dayrdnobilia JavaScript-is obieqtze saxelwodebit XMLHttpRequest.modit exla ganvixilot ufro dawvrilebit, tu ristvis gamoviyenebt AJAX-s, praqtikulad tu ras warmoadgens igi da rogor shecvlis saitis shesaxedaobasa da funqcionirebas. magalitistvis vtqvat, rom gvinda shevqmnat patara saiti, romelic dakavshirebulia monacemis bazastan da inaxavs uamravi manqanis models. saitze shesvlisas unda gamodiodes dziebis forma, romlis shevsebisa da ghilaki dziebis dacheris shemdeg unda gamochndes rezultati. albat vinc kitxulobt am artikls fiqrobt, amas xom araferi ar unda; ubralo HTML forma, romelic GET an POST parametrebs miawodebs serverul skripts, skripti monaxavs miwodebul parametrebs monacemta bazashi da axal gverdze gamoachens rezultats. modit am patara magalits sxva kutxit shevxedot. gvaqvs patara saiti, mxolod erti martivi funqciit, nutu sasiamovnoa momxmareblistvis formis shevseba, ghilakze dachera, shemdeg lodini sanam skripti modzebnis msgavs rezultats da sabolood axali gverdis chatvirtva masalis sanaxavad? albat ifiqrebt, rom sxva gza araa, ras izam? swored aseti problemebis gadasachreladaa AJAX-i. mas sheudzlia parametrebis ise gagzavna, rom momxarebelma verc ki shenishnos, axali gverdi ar chaitvirtos da ise daematos gverds rezultati. tu zemot moyvanil magalits AJAX-it gavaketebdit, mashin suratistvis shesadzlebeli iqneboda shemdegnaeri saxe migveghebina. momxmarebeli shedis saitze, xedavs shesavseb formas saxelad "avtomobilis mwarmoebeli", momxarebels surs modzebnos BMW-s yvela modeli, amitom iwyebs shevsebas. daachira tu ara klaviaturaze ghilak "B"-s formis qvemot uceb gamochnda didi chamonatvali dawyebuli avtomobili "Bentley"-is mravalimodelit da gagrdzelebuli BMW-s modelebit. shemdeg momxmarebelma daamata aso "M" da Bentley-is yvela modeli gauchinarda, darcha mxolod BMW-s modelebi. dametanxmebit rom formis eseti funqcionireba gacilebit ufro mosaxerxebelia vidre klasikuri POST/GET parametrebis gamoyeneba. es metodi saits ufro megobruls xdis momxmareblis mimart da umartivebs saqmis ketebas. --------------- A,N,R,I 29 სექტ 2013, 22:27 albat ukve mixvdit tu ra aris Http Request-is mtavari amocana. igi uzrunvelyofs monacemebis gagzavnas "chum rejimshi". shemdeg tavshi ukve gadavalt praqtikul nawilze da viswavlit tu rogor vixmarot AJAX-i ukve JavaScript-shi cocxal magalitze. XMLHttpRequest-is gamodzaxeba upirveles yovlisa, unda aghinishnos faqti, yvela brauzers gaachnia AJAX-is XMLHttpRequest-is gamodzaxebis tavisebuli metodi. es iqedan gamomdinareobs, rom obieqti chawerilia tviton brauzershi. zogan is klasad aris aghwerili, zogan bibliotekad, zogan ki rac jer ar shemxvedria sheidzleba funqciatac ki iyos. Internet Exporer-i XMLHttpRequest-istvis iyenebs ActiveXObject-is bibliotekas, romelshic shedis chveni obieqti, sxva brauzerebis umetesobas ki gaachnia calke klasad chadgmuli XMLHttpRequest-is obieqti. AJAX- ze mushaobamde aucilebelia XMLHttpRequst-is gamodzaxeba, rac sheidzleba ganxorcieldes mravali gzit, imis gamonaklisit rom yvela gamodzaxebashi sheva sausurveli brauzeristvis damaxasiatebeli funqcia. chemi piradi gamocdilebidan mgonia, rom FireFox, Safari da Opera iyenebs erti da igive klass da am brauzerebshi gamodzaxeba xdeba shemdegi brdzanebit new XMLHttpRequest (); Internet Explorer-shi saqme cota ufro rtuladaa, 6.0 versiidan gamodzaxeba xdeba shemdegnaerad: new ActiveXObject ("Msxml2.XMLHTTP"); xolo 5.5 versiashi iyo new ActiveXObject ("Microsoft.XMLHTTP"); albat cota daibenit,magram araushavs, male yvelaferi bevrad gasagebi gaxdeba. rasakvirvelia zemot chamotvlili gamodzaxebebi minichebuli unda iyos raime cvlads, magalitad var XMLHttpObject-s. AJAX-is gamodzaxebis odnavi sirtulis gamo gadavwyvite warmogidginot chemi gamodzaxebis xerxi. gaitvaliswinet, rom momdevno kodis interpretacia sheidzleba dzalianmravali gzit, es ubralod ert-erti modelia. 1. --------------- A,N,R,I 29 სექტ 2013, 22:28 albat mixvdit gamodzaxebis fundaments, me gamoviyene try / catch metodi, tqven shegidzliat cadot if / elseif / else metodi an switch / case. im shemtxvevashi tu es funqcia ar daabrunebs "false"-s mashin ukve mzad vart vimushaot AJAX- shi im cvladtan ertad romelsac mivanichet obieqti. chven shemtxvevashi es aris cvladi XMLHttpObject. yvela momdevno moqmedeba ganxorcielebuli iqneba swored am cvladis gamoyenebit. monacemebis migheba serveridan xmlHttpRequest warmoidginet klasad, mravali metodita da cvladit. upirveles yovlisa unda itqvas, rom mas gaachnia sami dziritadi mdgomareobaeseni arian onReadyStateChange, readyState da responseText. am tavshi samives cal-calke ganvixilavt. --------------- A,N,R,I 29 სექტ 2013, 22:30 logikuria, rom mas shemdeg rac AJAX-i gaugzavnis brdzanebas an monacems serverul skripts, unda arsebobdes raghac funqcia, romlis meshveobitac moxdeba im monacemebis migheba rasac serveri gamoushvebs pasuxad. swored es danishnuleba gaachnia mdgomareoba onReadyStateChange-s, romelic uzrunvelyofs programistis mier specifiuri funqciis gashvebas specifiur serverul skripttan mimartebashi swored im wams, rodesac monacemis mighebis mdgomareoba icvleba. magalitistvis da praqtikuli gamocdilebistvis warmoidginet, rom xmlHttpObject aris cvladi romelic warmoadgens xmlHttpRequest-s da gvsurs davichirot specifiuri momenti rodesac serveridan monacemi modis. 1. xmlHttpObject.onreadystatechange = function() 2. { 3. // Aq ukve cava specifiuri samushao 4. } albat am magalitma odnav dagabniat, magram es logikuricaa, unda arsebobdes ramdenime mdgomareoba, romlis dacherac gvinda. es mdgomareobebi motavsebulia tvisebashi saxelad readyState. is ganicdis cvlilebas yovel etapze rodesac serverisa da klientis urtiertkavshiri icvleba. readyState-s gaachnia xuti mdgomareoba eseni arian: 0 - brdzaneba ar gacemula 1 - brdzaneba momzadda 2 - brdzaneba iqna gagzavnili 3 - brdzaneba sruldeba 4 - brdzaneba shesrulebulia imedia mixvdit, rom im momentshi rodesac readyState-is mdgomareoba icvleba xdeba onReadyStateChange-ze mititebuli funqciis gashveba. ai wina magalitis ganvrcobili versiac. 1. xmlHttpObject.onreadystatechange = function() 2. { 3. var status; 4. if (xmlHttpObject.readystate == 0) status = "Ar gacemula"; 5. if (xmlHttpObject.readystate == 1) status = "Momzadda"; 6. if (xmlHttpObject.readystate == 2) status= "Gaigzavna"; 7. if (xmlHttpObject.readystate == 3) status = "Sruldeba"; 8. if (xmlHttpObject.readystate == 4) status = "Shesrulda"; 9. alert(status); 10. } --------------- A,N,R,I 29 სექტ 2013, 22:31 exla ki gadavdivart mesame da yvelaze mnishvnelovan cvladze responseText. tu wina magalitshi raghacas velodebodit da misi shesruleba mdgomareobebadac ki gadavanawilet, eseigi martlac yvelaze mnishvnelovani raghaca gvedga win. es gaxlavt is cvladi romelic daabruna pasuxad serverma! rodesac readyState 4- is tolia, responseText cvladis gamoyeneba ukve shesadzlebelia chveulebrivat, ise rogorc JavaScript-shi gamoiyenebdit nebismier cvlads. imedia imasac mixvdit, rom xshirad saitebze chatvirtvis surats roca xedavt mag dros readyState swored 3-is tolia. 1. xmlHttpObject.onreadystatechange = function() 2. { 3. if (xmlHttpObject.readystate == 3) document.getElementById ('mdgomareoba').innerHMTL = "Itvirteba..."; 4. if (xmlHttpObject.readystate == 4) document.getElementById ('mdgomareoba').innerHTML = xmlHttpObject.responsetext; 5. } monacemebis mighebastan dakavshirebit sul es iyo, shemdeg tavshi ki gavecnobit monacemebis gagzavnas. monacemis gagzavna serverze monacemis gagzavna dzalian martivia. amistvis viyenebt XMLHttpRequest-is or metods open() da send(). upirveles yovlisa gavarchevt orive funqcias, shemdeg ki gadavalt magalitze. open() funqcias gaachnia sami argumenti. pirveli argumenti gansazghvravs tu ra metodit moxdes brdzanebis gacema, POST-it tu GET-it. meore argumentshi shedis serveruli skriptis misamarti, xolo mesame argumenti gansazghvravs brdzaneba mirebuli unda iyos asinqronulad tu ara. umetes shemtxvevashi mesame argumentis mnishvneloba true-a. send() metodis danishnuleba, saxelidan gamomdinare aris, rom gaagzavnos brdzaneba serverze. imisatvis, rom uket mixvdet tu rogor mushaobs gagzavnis metodi warmogidgent pataraskriptis fragments. 1. xmlHttpObject.open("GET", "http://soft.ge/ajax/server.php? returnName", true); 2. xmlHttpObject.send(); --------------- A,N,R,I 29 სექტ 2013, 22:32 Ajax ar aris axali programirebis ena, magram is aris uketesi, ufro swrafi da interaqtuli veb programebis sheqmnis teqnologia. am enis shesaswavlad sachiroa HTML / XHTML da JavaScript-is codna. Ajax-is daxmarebit JavaScript-s sheudzlia daukavshirdes servers XMLHttpRequest obieqtis gamoyenebit. am obieqtis daxmarebit, JavaScript-s sheudzlia ivachros veb serverit, gverdis ganaxlebis gareshe. Ajax iyenebs asinqronizebul monacemta gadacemas brauzersa da veb servers shoris da sashualebas adzlevs veb gverds serveridan moitxovos informaciis mxolod is bitebi, romlis mimoxilvac surs momxmarebels. Ajax teqnologia internet porgramebs aqcevs ufro patara, swraf da momxmarebelze morgebul programebad. ---------------