I have some some JQuery code that is attached to an image's click event. The image has a href value attached to it. That part works well. When the button is clicked, the JQuery does an AJAX call to another script, which returns a value, and sets that value to variable called 'data'. That part works well. The function then checks if the value (a string) is 'TRUE' or 'FALSE'. That part works well.
What I then want to do is, if the value of 'data' is 'FALSE', then I want to prevent the user from leaving the page (ie, 'return false;', and override the href on the image). If the value of 'data' is 'TRUE', then I want the user to sail on through to the next page (ie, just don't do a 'return false'; ).
This fails:
And this fails:HTML Code:<script type="text/javascript"> $(document).ready(function() { $('.print_btn').click(function() { $.get('some_script.php', { val1 : "2", val2: "30" }, function(data) { if (data == 'TRUE') { alert ('TRUE'); } else { alert ('FALSE'); return false; } }, 'text'); }); }); </script>
HELP?HTML Code:<script type="text/javascript"> $(document).ready(function() { $('.print_btn').click(function() { $.get('some_script.php', { val1 : "2", val2: "30" }, function(data) { if (data == 'TRUE') { alert ('TRUE'); } else { alert ('FALSE'); } }, 'text'); }); if (data == 'FALSE') { return false; } }); </script>


Reply With Quote
Bookmarks