My js:
$('#select').change(function() {
var name = $(this).val();
$.ajax({
type: "POST",
url: "data/grab.php",
data: { type: "hops", name: name },
dataType: "json",
success: function(data) {
alert(data);
var aa = data['aa'];
$('#hops-aa').val(aa);
}
});
});
grab.php
<?php
$type = $_POST['type'];
$name = $_POST['name'];
if ($type == 'hops') {
$result = $name;
}
$result = json_encode($result);
return $result;
I added the alert() in the ajax call to double check what I’m getting back from the script, and it’s always null. Anything I’m missing?
You need to actually
echoorprintthe$result. In PHP usingreturnfrom the file scope does not send the returned value to the output stream.