hello i want to pass the value of a function to any other function or make the value of a function global so that it can be called in any other function . but i dnt knw how to do it , tried some codes still no sucess .
here is the function code
function newalbum(val1,loginuser)
{
$.ajax({
type:"GET",
url: 'ajax/album.php?val='+val1+'&& loguser='+loginuser,
success: function(data) {
$("#newalbum1").html(data);
var ab=$('#ab').val();
var abc=$('#loginuser').val();
var action=$('#action').val();
alert(ab);
}
});
}
in this function i want to make the three variables var ab, var abc, var action to be global so that its value can be used in any other function . can any one help?
edit – the value of var ab, var abc, and var action is comming from ajax data that is why i am not able to use those variable directly , it says undefined if i use it directly.
after the varibales value received from ajax in function newalbum . i want to use those varibales inside
(function( $ ){
$.fn.Uploadrr = function( options ) {
You can declare the variables in the global scope, and remove
varbefore theab,abcandactionvariables. Another method is to prefix the variables withwindow, the global object.Method 1:
Method 2:
Note: Unless you’ve got an extremely good reason for it, you usually should not declare global variables.