I have an ajax call and i get a json response from it, this is an example of the response
{"Title":"test", "price":"65.31"}
and here is my code
add_action('admin_head', 'apm_get_single_field');
function apm_get_single_field() {
?>
<script type="text/javascript" >
function apm_get_single_field(field_name, requested_data, asin_field, amazon_domain) {
$.ajax({
type: "POST",
url: ajaxurl,
dataType: "JSON",
data: {
action: 'apm_get_single_field',
postId: <?php echo get_post()->ID; ?>,
field: field_name,
requested_data: requested_data,
asin: document.getElementsByName(asin_field)[0].value,
amazon_domain: amazon_domain
},
success: function(Lookup_Data) {
document.getElementsByName(field_name)[0].value = Lookup_Data.price;
$('#apm_status_' + field_name).text("Retrived").css('color', '#04b600').fadeIn().delay(1000).fadeOut();
}
})
};
</script>
<?php
}
so as you can see on the above code i called the price value by using "Lookup_Data.price" which worked perfectly however what i need is to replace the ky 'price' by js variable 'requested_data' which you can see in the function arguments. i tried Lookup_Data.requested_data and Lookup_Data. + requested_data which didnt work.. guess because my pc try to search for an array key called requested_data which couldnt find because requested_data is not a key its a variable.