Home > Software design >  How to tell ajax to run particular URL only when a pop up banner is clicked?
How to tell ajax to run particular URL only when a pop up banner is clicked?

Time:05-26

I am trying to pop-up a feedback banner, when a particular page is loaded. Here is the code for that

$(window).on('load', function() {
    $('#review_modal').modal('show');
});

Now I want if someone clicks any button of pop up banner, (either Give feedback or No thanks) it runs a particular URL which only does is (Never show that user feedback again)

Here is my code for that which is wrong

$(window).on('click', function() {
        $.ajax({
            type: "POST",
            url: "/update_feedback_status",
        });
    });

I am very very new to ajax, but I need this to be done as soon as possible. How should I fix it? HO wto tell ajax that On click means clicking on the button of that popup banner which is #reviewmodal

Thanks

CodePudding user response:

You should add the click event listener to the elements in popup model instead of window.

For example:

<div id="review_modal" >
    <button>Give feedback</button>
    <button>No thanks</button>
</div>

<script>
$('#review_modal button').on('click', function() {
    $.ajax({
        type: "POST",
        url: "/update_feedback_status",
    });
});
</script>
  • Related