logo
down
shadow

jQuery Ajax triggering 2 events together from single click


jQuery Ajax triggering 2 events together from single click

By : Anuj Agrawal
Date : November 22 2020, 02:59 PM
This might help you It may work if you move your "else" statment to where it belongs. but the better way would be break it into multiple functions. This makes it easier to understand and maintain.
code :
$(document).ready(function() {
        $("#trigger").click(function(e) {
            var text = $(this).data('text');
            var agree = confirm(text);
            if (!agree){
                return false;
            }
            runAjax();
        });

    });

function runAjax(){
    var getcururl = window.location.href;
    var testid = $('#testid').val();
    $.ajax({
        method: 'POST',
        url: 'test.php',
        data: {
            getcururl: getcururl,
            testid: testid
        },
        success: function(data) {
            if (data != '') {
                alert(data)
            }
        },
        error: function(data) {
            alert('Something went wrong, Please contact admin');
        }
    });
}


Share : facebook icon twitter icon
jQuery: Is it possible to group several events into a single .click()?

jQuery: Is it possible to group several events into a single .click()?


By : YJ Disu
Date : March 29 2020, 07:55 AM
wish helps you I have the following code which processes a click from a tab and loads contents via ajax:
code :
$(document).ready(function()
{
    $("#tab1, #tab2, #tab3, #tab4").click(function()
    {
        loadTab($(this).attr("href") + "?ajax=1");
        return false; // cancel the event
    });
});
$(document).ready(function()
{
    $(".tab").click(function()
    {
        loadTab($(this).attr("href") + "?ajax=1");
        return false;
    });
});
$(document).ready(function()
{
    $("#tabs").click(function(e)
    {
        if (!$(e.target).is('.tab')) return;
        loadTab($(this).attr("href") + "?ajax=1");
        return false;
    });
});
$(document).ready(function()
{
    $("#tabs").delegate('.tab', 'click', function()
    {
        loadTab($(this).attr("href") + "?ajax=1");
        return false;
    });
});
$(document).ready(function()
{
    $("#tabs").delegate('.tab', 'click', function()
    {
        loadTab(this.href + "?ajax=1");
        return false;
    });
});
Triggering click events in JQuery

Triggering click events in JQuery


By : Creedy
Date : March 29 2020, 07:55 AM
it helps some times And here we have an answer. Like the comments say, you can do this much more simply than you're currently doing it. My way is just one of the ways. The code should be fairly self explanatory.
HTML
code :
<table>
    <tr>
        <td><input type="radio"name="radio"></td>
        <td class="label">Row 1</td>
    </tr>
    <tr>
        <td><input type="radio" name="radio"></td>
        <td class="label">Row 2</td>
    </tr>
    <tr>
        <td><input type="radio"name="radio"></td>
        <td class="label">Row 3</td>
    </tr>
</table>
$(document).ready(function() {
    $("td.label").click(function() {
        $(this).parents("tr").addClass("selected").siblings().removeClass("selected");
        $(this).parents("tr").find("input").click();
    });

    $("td > input").click(function() {
        $(this).parents("tr").addClass("selected").siblings().removeClass("selected");
    });
});
.selected td
{
    background-color: #e1e1e1;
}
Update HTML Element Associated with Click Event Triggering JQuery AJAX Request

Update HTML Element Associated with Click Event Triggering JQuery AJAX Request


By : Reza Ataiy
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have several HTML elements (buttons) that fire the same JQuery AJAX request. When the AJAX request returns successfully, I need to make some updates to the HTML element that triggered the AJAX request. I understand how to do this if I were to hardcode the id of the element to update, such as an item with an id of myDiv as shown in the code below, but I am unsure of how to handle a dynamic id that corresponds to the element that triggered the event.
code :
$('body').on(
'click',
'#yt25',
function(){
    var _this = this;
    jQuery.ajax({
        'type':'POST',
        'data':$("#custom-hazard-form").serialize()+"&ajaxRequest=hazard-form",
        'success':function(data) {
            $(_this).html('This is the new text'),
        }
        'url':'#',
        'cache':false
 });
return false;
});
Button Click not triggering jQuery(Ajax) function to update page

Button Click not triggering jQuery(Ajax) function to update page


By : Francesca giuffrida
Date : March 29 2020, 07:55 AM
may help you . There are a couple of issues with your code that I see:
You should not wrap the data parameters into single quotes. Your success and error parameters should not be strings. They should be functions You should never hardcode urls in an ASP.NET MVC application. You should always use url helpers when dealing with urls
code :
$("#Button1").click(function() {
    var link = '<%= Url.Action("DisplayStudentName", "Student")';
    $.ajax({
        url: link,
        data: { id: '<%= ViewContext.RouteData.Values["id"] %>' },
        success: Success,
        error: Fail
    });
});

$("#Button2").click(function() {

    var link = '<%= Url.Action("DisplayStudentStatus", "Student")';
    $.ajax({
        url: link,
        data: {
            id: '<%= ViewContext.RouteData.Values["id"] %>' , 
            flg: '<%= ViewContext.RouteData.Values["flg"] %>' 
        },
        success: Success,
        error: Fail
    });
});
function Success(data) {
    // ...
}

function Fail() {
    // ...
}
jQuery: Triggering .click() events, one after the other

jQuery: Triggering .click() events, one after the other


By : Bianca B
Date : March 29 2020, 07:55 AM
Any of those help inside your first handler you could use a deferred object, resolve it in the ajax success callback and return a promise so you would chain your code like this (I haven't tested)
Related Posts Related Posts :
  • Check each paragraph contains any bold element with jQuery
  • Bootstrap- background image with content overlay
  • Owl carousel not getting responsive
  • Working with css before selector
  • How to make flowcover like image slider(jquery editing)
  • how to make ajax call onclick of checkbox
  • When fetching data from multiple JSON files with different number of data columns it returns undefined and breaks loop,
  • Send multiple value on manually triggered event jQuery
  • Creating an image element (modifying the DOM)
  • Not able to display properly the hyperlinks because style=display:none
  • jQuery $('img[alt]') vs. $('img').attr('alt')?
  • How do I make a Modal Dialog Box Auto Open after 2 seconds?
  • Adding only one title at a time to the table header in jquery
  • Matched set results relative to another selector
  • How to increase jqgrid header checkbox size
  • Compile directive within controller and return html to DataTable's render function
  • how to change each consecutive div order?
  • Replace submit button value with ASCII character
  • Make mmenu expand to the current url
  • Uncaught TypeError: "#submitRates".click is not a functio
  • ACF Tag It Field and createTag
  • Original filename in case of error in jQuery File Upload
  • Cycle through an HTML list with jinja and jQuery?
  • jQuery UI draggable and sortable not working
  • jquery access dynamically generated form
  • Typeahead - Unable to use dynamically created array as source of data
  • Toggle other specific classes off when toggling one on
  • Changing aria-label for ascending and descending states on a sortable table with Jquery
  • Sending var with load jquery
  • How to wrap all siblings in one class after a class? (jQuery)
  • Appending an object to serialized form data
  • how to replace jquery to jquery mobile
  • jquery show/hide buttons on same row not showing pretty - causing half hight during animation?
  • <select> change event doesn't work
  • jQuery hover/click on desktop and mobile devices
  • Use Jquery and FormData to submit form fields and uploaded File to Spring MVC Controller in Spring Boot App
  • Is there a smart way to simplify these jquery codes?
  • JQuery File Upload middleware - Image versions not creating
  • How to increase cookies storage limit(4096) in chrome
  • div on translating increases page width
  • How do I set shipping value depending on select & checkbox
  • jQuery change active state of multiple elements on page when different categories are selected
  • rails jquery script does not work when clicking link
  • Array of JQuery Selectors
  • how can I target with jquery this element?
  • Display default date based on time in jquery datepicker
  • Changing date format before binding JSON data to a jquery template
  • How to use load and open in same div
  • How to make position fixed div scroll horizontally?
  • save state the list on page refresh
  • Change the value of many Divs on select of drop-down
  • Background-image transition not working
  • http request inside another http request success response not working in jquery
  • jQuery hover is not working when I use display:none property of my input
  • Limit jQuery toggle to only affect one accordion
  • Changing div values when dropdown is selected
  • How to replace a list of images with jQuery?
  • jQuery Clone / Copy Style attributes of first td of Table to another Tables's first td
  • Why my select only get the last value?
  • fullpage.js multiple onLeave and afterLoad events
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co