I have a totalPrice
variable in JavaScript:
var totalPrice = 0;
With AJAX, I send a request to a server and I get my result from it, and I want the server result to be assigned to totalPrice
:
$.request('onGetProductId', {
data: { productId: productValue },
success: function (data) {
totalPrice = data.result;
}
});
alert(totalPrice) // This line i want to get server's response but i get zero.
When I call totalPrice
out of AJAX I get 0 value but I want to get value in data.result
. How can i fix it?