- Joined
- Jan 6, 2022
- Messages
- 2
- Reaction score
- 0
I have made 30 attempts to try and update my global variable but it keeps saying undefined. I've tried setting a timer function, passing the response to a another function, etc. Can someone please tell me how to fix this?
JavaScript:
(function (d) {
var jsonobjvar; // < -- stays undefined
jQuery(document).ready(function ($) {
var data = {
'url': 'ajax.php',
'action': 'my_other_action', // arbitrary
'whatever_other': name // arbitrary
};
// making a response alert with the data
jQuery.post(data.url, data, function (response) {
var jsonobj = $.parseJSON(response);
alert('Got this from the server: ' + response);
jsonobjvar = response;
jsonobjvar;
};
});
});
})(document);