Below is my javascript code.. I am declaring the variable 'allproductsAndPrice' outside the function.. But I am not able to access it after i initialize it.! Am i doing something wrong? when I try to alert it, It doesn't print anything.
var allproductsAndPrice = "";
$.getJSON("/Home/GetProducts",
    function (data, textStatus, jqXHR) {
        for (var i = 0; i < data.length; i++) {
            allproductsAndPrice = allproductsAndPrice + 
                "<option name='productName' id=" + data[i].productPrice + ">" + 
                data[i].Pname + "</option>";
        }
    }
);
alert(allproductsAndPrice);
 
     
     
    