Trigger custom JQuery


Difficulty

Today I show you a way to create custom triggers in case you need to trigger events dependent on others, perhaps not editable.
An example of utility is when you find yourself with external ajax calls or events not covered so you must still identify the moment of conclusion.

A couple of examples of the possibilities:
1) I show an alert when an ajax has loaded (in our case a test page):

$.when( $.ajax( "test.php") ).then(function(data, textStatus, jqXHR) {
  alert( jqXHR.status ); // Alerts 200
});



2) I show an alert to the valorization of a variable:

$.when( { testing: 123 } ).done(function( x ) {
  alert( x.testing ); // Alerts "123"
});


In our example, the variable is valued immediately but could be returned by an ajax call to which the event could be triggered.

0
Be the first one to like this.
Please wait...

Leave a Reply

Thanks for choosing to leave a comment.
Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published.
Please do NOT use keywords in the name field. Let's have a personal and meaningful conversation.