seems like a simple issue but the solutions to the other problem don't seem to work from me.
Trying to trigger a AJAX request from a button click but it doesn't seem to be firing.
example HTML
<button class="remove_weight_button" id="15">x</button>
javascript
$(".remove_weight_button").click(function(){ var button_id = $(this).attr("id"); $.ajax({ type: "POST", url: "weight_tracker_process.php", data: { weight_id: button_id, action: "remove" }, success: function(){ getWeightData(); }, error: function(){ alert("data removal error"); } }); return false; });
jQuery click not working at the time page loading, jQuery Onclick Method is tried to an element or selector. As a result, the binding will fail if the element we wish to click isn't present when the page is ready.
check the CausesValidation property of your button. set it to False if its true. Also check your asp.net page code file link is exactly same in which you have put the event. Is the button inside a template control (such as an <asp:Repeater> or <asp:GridView> )?
The code you have works fine in fiddle. Is your button being dynamically rendered through AJAX after the initial page load?
Use
$(document).on("click", ".remove_weight_button", function(){
instead of
$(".remove_weight_button").click(function(){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With