Amran
Amran

Reputation: 657

Call a function after POST

How do I call a jQuery function after the data is successfully post and display. Example is as below,

<script>
$(document).ready(function(){

    $("#pr_no").change(function(){
        var pr_no = $('#pr_no').val();  

        $.post('../view-detail-purchase-pdf.php',
        {
            pr_no : pr_no
        }, function(data) {
            $('#result').html('<a href="../view-detail-purchase-pdf.php?pr_no=' + pr_no + '" class="popupwindow">' + pr_no + '</a>');
        })

    }); 

});
</script>

On the $('#result') div is a link that enable a pop up window if click using a jQuery plugin that have the class="popupwindow". How do I make it work.

Upvotes: 0

Views: 2921

Answers (2)

madalinivascu
madalinivascu

Reputation: 32354

Since the link is dynamically added you will need to delegate the click event for you popup

$('body').on('click','.popupwindow',function(){
// code for showing the popup window
});

or if you have a plugin you define it in the success function

$.post('../view-detail-purchase-pdf.php',
        {
            pr_no : pr_no
        }, function(data) {
            $('#result').html('<a href="../view-detail-purchase-pdf.php?pr_no=' + pr_no + '" class="popupwindow">' + pr_no + '</a>');
           $('.popupwindow').initPopup();//initiate your popup after appending the element on the page;
        })

Upvotes: 1

Arun Prasad E S
Arun Prasad E S

Reputation: 10115

var jqxhr = $.ajax( "example.php" )
  .done(function() {
    alert( "success" ); // this is what you may be looking for
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "complete" );
  });

Upvotes: 3

Related Questions