Global variables in jQuery
Posted
by Thorpe Obazee
on Stack Overflow
See other posts from Stack Overflow
or by Thorpe Obazee
Published on 2010-04-23T02:08:54Z
Indexed on
2010/04/23
2:13 UTC
Read the original article
Hit count: 347
I have been working on this script:
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">
$(function(){
compentecy = $('#competency_id');
$('#add_competency').bind('click', function(e){
e.preventDefault();
$.post('/script.php', {competency_id: compentecy.val(), syllabus_id: 2}, function(){
// competency = $('#competency_id');
competency.children('option[value=' + compentecy.val() + ']').remove();
});
});
});
</script>
in the $.post callback function, it seems that I can't access global variables. I tried $.competency but it didn't work. I always get a "competency is undefined" error. I had to reinitialize the variable once again inside the callback. Is there a way to NOT reinitialize the variable inside the callback?
© Stack Overflow or respective owner