Reputation: 1272
I pretty much just want to pass a json object over to another function when it happens (for example a click event gets called).
$(document).on('click', '.some_link', function() {
var something = "something";
$.get('/someDirectory/someScript.php', {
'some_var': something
}}.done(function(data) {
var json = jQuery.parseJSON(data);
$('#json-item-container').val(json);
});
});
$('.hidden-input').click(function() {
var json = $('#json-item-container').val();
//Do something with json
});
Upvotes: 1
Views: 162
Reputation:
Store the json data in the global scope:
var json; // json var defined in global scope
$(document).on('click', '.some_link', function() {
var something = "something";
$.get('/someDirectory/someScript.php', {
'some_var': something
}}.done(function(data) {
json = data;
});
});
$('.hidden-input').click(function() {
console.log('Ohai! Im the json object: ' + JSON.stringify(json));
});
Upvotes: 1