Possible Duplicate:
How to return AJAX response Text?
How to return the response from an AJAX call from a function?
I am trying to get a record from SQL according to the value I send with ajax. But all I get is undefined when I console.log it.
jQuery:
function extraOptions(str){
$.get("inc/ajax/extra_options.php",
{q:str},
function(html){
return html;
}
);
}
$("#auto_model").change(function(){
console.log(extraOptions(this.value));
});
extra_options.php:
$q = $_GET['q'];
echo extra_options($mysqli, $q);
extra_options function:
function extra_options($mysqli, $q){
$query = "SELECT
extra_options
FROM
vozila_tbl
WHERE
Model_vozila = '".$mysqli->real_escape_string($q)."'";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
return $row['extra_options'];
}
Edit:
It should return 1 or 0 and if it returns 0 I want to change the updateField function with an if statement.
function updateField(str, id, prevvalue, value, vehicletype){
$.get("inc/ajax/form_rest.php",
{q:str, prevvalue:prevvalue, value:value, vehicletype:vehicletype},
function(html){
$('#'+id).html(html);
}
);
}
$("#auto_model").change(function(){
updateField(this.value, 'auto_bodywork', 3, 4, this.parentNode.id), resetBelow(2,'auto'), show('auto_bodywork');
});
The line I need to change in the if statement is:
updateField(this.value, 'auto_bodywork', 3, 4, this.parentNode.id), resetBelow(2,'auto'), show('auto_bodywork');