After extensive searching, I have been unable to find a solution. The code snippet below is responsible for making a database request and retrieving data through $.post. Even though the inner function successfully fetches the data, I require it to be accessible outside in order to assign some data to the outputString variable. The necessary steps are evident in the provided code.
function calculatePrice(checkInDate, checkOutDate, nights){
var rentDetailsArr = <?php echo json_encode($periods); ?>;
var minDays = ["<?php echo implode('","',$minDaysArr)?>"];
var outputString ="";
var stDate = "2010-02-10";
var endDate = "2010-09-29";
var xxx = $.post('testData.php',
{ opType:"getSelectedPeriodDetails", startDate: stDate, endDate: endDate },
function getData(data) {
$(data).each (function (index){
//I am able to get the data in here.but i need to equal it to outputString variable.
var price = data['period_id'][0];
//alert(price);
alert(price);
});
}, "json");
//when I equal $.post return to xxx variable, the return is as [object XMLHttpRequest ]
alert(xxx);
return outputString;
}
Now how I can handle the data out side?..can handle the data through xxx variable. If I can , how i will parse it? Sorry, if I have used wrong terms in explaining the problem. I am not very familiar with but I still can use.