I'm developing userscript for one webpage (aka browser plugin). I need to update one global Javascript variable (lets call it gVariable (it is an array)) with the one I get with ajax request.
In ajax request I'm requesting for the same page I'm on. But just want to "extract" that one global variable and replace current one with the one downloaded.
This is something I have now (not working).
function LoadNewItemList() {
$.get(window.location, function (data) {
var $data = $(data);
unsafeWindow.gVariable = data.gVariable; //I'm getting 'undefined'
});
}
JS test: http://jsfiddle.net/ywVKT/15/
window.locationwould have to point to a JSON structure in order to treatdataas a navigable object. When you load via AJAX you are just loading the page markup, not a rendered DOM like you would loading a new window...