PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 9, 2022

[FIXED] How to tell ajax to run particular URL only when a pop up banner is clicked?

 September 09, 2022     ajax, javascript, jquery     No comments   

Issue

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.


Solution

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

For example:

<div id="review_modal" class="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>


Answered By - 倪任爾
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing