Here i want to access the variable "finalPrice " in another function, how can i achive this?
function available(id){
$.ajax({
method:"GET",
}).done(function(data){
for(j=0; j<available_location.length; j++) {
var finalPrice =available_location[j].price_details.final_price;
};
});
function razorpay() {
$.ajax({
url : 'http://test4238.wickedride.com//api/cancelledEnquiries/add',
type : 'GET',
data : {
},
success: function(data){
alert(finalPrice );
}
});
}
Your
finalPrice
is scoped only to theavailable
function since that's where it's declared (var finalPrice
). In Javascript, if you want a variable to be accessable from all script scopes, move it outside the function, to the beginning of the script: