Link to home
Create AccountLog in
Avatar of peps03
peps03

asked on

Trigger ajax-call by clicking div

Hi,

I have 9 divs, if one is clicked an ajax-call should be triggered, sending the number 1-9 (corresponding with the number of the div) to the call. The ajax works fine, but i can't get it to fire when a div is clicked.

How should i do this? The methods i tried don't work.


Thanks
Avatar of IanTh
IanTh
Flag of United Kingdom of Great Britain and Northern Ireland image

Show us your code

you need an on-click JavaScript event in the div
Avatar of peps03
peps03

ASKER

$("#thumbpic1").click(function() {$('#playpp').trigger('click'); thumb = 1;});

if(thumb == 1 || thumb == 2 || thumb == 3 || thumb == 4 || thumb == 5 || thumb == 6 || thumb == 7 || thumb == 8 || thumb == 9){             
                                    
            $.ajax({
                  type: "POST",
                  data: "album=" + thumb,
                  url: "getselect.php",
                  success: function(msg){
                        if (msg != ''){
                              $("#gallery1").html(msg);
                        }
                        else{
                              // Some error handling in case nothing is returned
                              $("#gallery1").html('Error..').show();
                        }
                  }
            });      // close ajax
      
      };
$("#thumbpic1").click(function() {$('#playpp').trigger('click'); thumb = 1;});

so whats you css
Avatar of peps03

ASKER

why you need to know any css?

this function show work right? or does it contain errors?
#thumbpic1 is the target for the click event
Avatar of peps03

ASKER

no.. the source. #thumbpic1 is the id of the div being clicked.
yes ie target but you have multiple divs so shouldn't the target be a container around the 9 divs
Avatar of peps03

ASKER

don't mind that. say i have 1 div, if it is clicked, 'var thumb' must become 1, and the ajax call triggered, how should i do that?
thats all, if i trigger the ajax call manually, it works.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of peps03

ASKER

Thank you ChrisStanyon!
That did the trick!