1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ajax div action script ?

Discussion in 'PHP' started by vetrivel, Jul 9, 2009.

  1. #1
    Hi ,
    I have a button inside a div and
    when i clicked that button , ajax request is made and loading the response inside a div where my button is available .
    How the response text have the same button but it didn't call the ajax .


    EX:
    <div id="iamdiv">
    <input type="text " name="name" >
    <input type="button" name="iambutton" />
    </div>

    now
    -> for onclick event i used jquery to call the ajax
    ->and ajax response contain :
    <input type="text " name="name" >
    <input type="button" name="iambutton" />
    and added it to the div using .html option in jquery

    ->But after the first ajax call it didnt trigger the onclick event function.

    Why so?

    How to overcome this.
    But this works fine when i use the simple ajax request and the onclick button attribute.
     
    vetrivel, Jul 9, 2009 IP
  2. daringtakers

    daringtakers Well-Known Member

    Messages:
    808
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Events are not binded to your new AJAX loaded elements. To solve this problem you need to bind events to your newly loaded elements.

    Use an ajax callback function to bind events to loaded elements

    Example

    
    $.ajax( 
            { 
                url: "google.com", 
                success: function(response) 
                { 
                    $("#container").empty().append(response); 
                    $('#container .my-button').click(...);
                } 
            });
    
    Code (markup):
     
    daringtakers, Jul 9, 2009 IP
  3. vetrivel

    vetrivel Peon

    Messages:
    147
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi ,
    Could you please provide me a example to do so.

     
    vetrivel, Jul 9, 2009 IP
  4. daringtakers

    daringtakers Well-Known Member

    Messages:
    808
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Can you see the example now !!
     
    daringtakers, Jul 9, 2009 IP
  5. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    koolman, Jul 9, 2009 IP