Jquery ajax | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Jquery ajax

Hi guys , iÔÇÖm try to make a search bar uses jqueryÔÇÖs .load function . It loads some few info into div #1 when writing something in search bar . Now i want to add .onclick function for each info row of result to show more info in div #2 . How should it be ? Where to write the code ?The front page or back-end file ? (And i think xmlhttprequest canÔÇÖt do the job.can it ? )

17th Sep 2019, 5:20 PM
3 Antworten
+ 3
On both sides. You will have again Ajax call to the server to get results on div1 click. So you have to bind to click event on that div + on the server side you have to create another web method to get that info in json or XML
17th Sep 2019, 7:48 PM
Dejan Dozet
Dejan Dozet - avatar
+ 1
de do tnx pal some lights turned on
17th Sep 2019, 8:46 PM
+ 1
I assume it is an Select2 dropdown. Select2 has its own implementation on keypress calls the back-end. Also you can add an 'change' event and that calls another endpoint from back-end to get data and populate your div 2. OR If you want to create an list inside div 1 you can also get the elements and create onclick events dinamically and with indexers to get the right element from list in order to know exactly what element its pressed in order to make call for pulling data and populating div2 this way is not that clean and easy to acieve with a framework like angular, react, vue. I would not recomend jquery because it can become messy and hard to mentain. good luck ^^
18th Sep 2019, 8:27 PM
Catalin Popinciuc
Catalin Popinciuc - avatar