FoxSecrets
Active member
I am searching for part of a username and copying the returned list to a select field just as example and am getting error 400 Bad Request on ajax call. Did not find any clear solution on old threads. Can someone help me to solve that?
AJAX:
PHP:
AJAX:
Code:
function search() {
var user = $("#user").val();
$.ajax({
url: "{{ link('my-page/search') }}",
method: "POST",
data: { username: user },
success: function(data) {
$("#result").val(data);
},
error: function(res){
alert("Error: " + res.status + " " + res.statusText);
}
});
}
PHP:
Code:
public function actionSearch()
{
if (isset($_POST['username'])) {
$username = $_POST['username'];
$finder = \XF::finder('XF:User');
$result = $finder->where('user_name', $username)->fetch();
if ($result->count() > 0) {
echo $result;
} else {
echo "No users found.";
}
}
}
Last edited: