Background: I have to show product options existing in database in a form. every product has multiple options and every option has multiple values. I have 2 functions, one to fetch product options, and the other to fetch values related to an option. I am calling the second function inside the first.
Problem: while OptionValues function in getting a correct JSON Response, i am not able to pass response values correcty to the getProductOptions function in order to show them.
Option values function:
function optionV(option_id){
var dataString = 'option_id=' + option_id ;
$.ajax({
type: "GET",
url: 'index.php?route=new/orders/OptionValues',
data: dataString,
cache: false,
dataType: 'json',
success: function(values) {
return values;
}
});
}
getProductOptions function :
function getProductOptions(sku){
// remove previous content in #options div
document.getElementById('options').innerHTML = "";
var dataString = 'sku=' + sku ;
// Get product options
$.ajax({
type: "GET",
url: 'index.php?route=new/orders/productOptions',
data: dataString,
cache: false,
dataType: 'json',
success: function(data) {
var options = '';
//loop through options to get values and show
for (var i=0 ;i< data.length;i++) {
//call function optionV to get option values
var optionVal = optionV(data[i].ID);
alert (typeof(optionVal));
}
});
}
the alert says : Undefined. and any attempt to access the optionV result in the other function is failing.
I have already tried stringify and json.parse
What should I do?