Hey guys,
I am new to JS/Ajax and would love some help if possible. I am not sure how to POST my form using Ajax rather than using the action="http://example/api/register_user.php" on the form to post form fields then display the response from the URL. If I post the from using the action="http://example/api/register_user.php" it sends me to that white page with a response like "Invalid Username" and I want to handle those responses in the same page. Here is an example of what I am trying to do, just not sure if I am on the right path or what to do:
<script type="text/javascript">
$(document).ready(function() {
$("#form").submit(function() {
$.ajax({
url: 'http://example/api/register_user.php',
type:"POST",
data:$("#form").serialize(),
success: function(data) {
//do something here like add response to a div called message?
});
});
return false;
});
</script>
Any help will be greatly appreciated! Thank you :)