How can I get the variable’s value from a plguin or send the value out from the plugin?
For instance this is my plugin which retrieves user information via ajax and it stores the user information in the variable,
(function($){
$.fn.extend({
get_authentication: function(options) {
var defaults = {
file: 'authentication_json.php',
location: 'cms/'
}
var options = $.extend(defaults, options);
var o = options;
var object = $(this); // now the object is the selected element such as #popup
$.get(http_root + rp_cms+ o.file, function(data){
if(data) var user_id = data.user_id;
// Redirect if the date returns as 'expired'.
if(data && data.error == 'expired') window.location = http_root + o.location;
//alert("Data Loaded: " + data);
},"json");
}
});
})(jQuery);
I call this plugin when I click on a certain links,
$('.get-user').click(function(){
$.fn.get_authentication();
alert(user_id);
});
I get an error like this.
Any ideas?
i added a callback to your plugin. Here’s an example + modified code