Saturday, 15 August 2015

javascript - Why is a "self" reference required to call ajax from within a jQuery dialog? -



javascript - Why is a "self" reference required to call ajax from within a jQuery dialog? -

the next jquery function opens tutorial dialog if specific pattern detected. added "do not show again" checkbox, user can decide don't want see popup anymore, included ajax phone call set session variable store setting. had problem getting ajax phone call work until added "this" reference. know why "this" needed? #userdismiss should select input corresponding id, , i've confirmed id used else in codebase project. below code works, i'm new jquery , interested in learning more why works written.

jquery code fragment:

$('#tutorial').dialog ({ show: "fade", title: "helpful hint", modal: false, close: function(event, ui) { if ($('#userdismiss', this).is(':checked')) { $.ajax ({ type: 'post', url: '/ajax/do-not-show-again.php' }); } }, buttons: { okay: function() { $(this).dialog('close'); } } });

and php snippet containing div used dialog in above jquery code

<div class="no-disp" $tutorial> <p>this tutorial message</p> <br /> <input id="userdismiss" type="checkbox" name="dismiss">don't show me again</input> </div>

because doing someting "$(this).dialog('close');" or testing status on element receiving evenement "event"

javascript php jquery ajax

No comments:

Post a Comment