I'm searching for access a window object into a function (actually, an ajax callback function but nevermind). So, I found a tuto where the guy explain my problem and why I have this problem but he doesn't resolve it.
Well, when I want to access the window object and I create an alert, the variable is undefined. And I understood why (I think). It's because when the global variable is in a function, everything in this function is protected.
Here is his code :
(function(){
var foo = "Hello, window";
var bar = function(){
var foo = "Hello, function";
alert(window.foo);
};
bar();
}());
So, my problem is quite the same. I have an object (with handsontable but it isn't important).
var hotTraitement = new Handsontable
I define it in global. So it can represent foo = "Hello, window"
. And I'm trying to use it in my callback function :
function callback(){
alert(window.hotTraitement);
}
And it's undefined. So I don't know how to do to get my object in my function and the tuto doesn't explain it. Can someone help me please ?
(If someone wants it, here is the link of the tuto : https://www.youtube.com/watch?v=VSgSNQ1-KBo&spfreload=10 )
EDIT :
This is my entire code :
<script>
//Where I define my object "hotTraitement"
var container = document.getElementById('tab_traitement');
var hotTraitement = new Handsontable(container, {
data: data_traitement,
stretchH: 'all',
minSpareRows: 1,
observeChanges : true,
rowHeaders: false,
colHeaders: false,
contextMenu: true
});
</script>
//The function where I want to get that object
<script>
function insertTraitementCallback(responseObject,ioArgs)
{
alert(hotTraitement);
}
</script>
//My ajax request where I call my callback function
<script type="text/javascript">
$(document).ready(function()
{
$('#submit_button_traitement').click(function()
{
$.post("ajaxUpdate.php",{arr:data_traitement,id_essai,table,idTable}, insertTraitementCallback,'json');
});
});
</script>