I'm sending a $.post request to php with jQuery. The jQuery code looks like this:
$('form').submit(function() {
username = $('input[name="username"]').val();
alert(username);
$.post('/ajax/new_user.php', {username:username}, function(data) {
alert(data);
});
});
In PHP, I'm just trying to do this for now:
<?php
echo $_POST['username'];
?>
The first alert in jQuery worked and prints the correct value, however the alert(data)
always alerts and empty string ("").
The file path is correct. I'm doing many other AJAX requests on my site that work perfectly so I'm not sure what makes this one so different. Any help is greatly appreciated!