Hi all,
I'm having some serious issues with AJAX forms. I'm currently using jQuery 2.2.0 and the jQuery Form plugin.
I have a simple php file:
<?php
if(isset($_POST)):
print_r(json_encode($_POST));
endif;
?>
I have a simple html form:
<form method="post" id="regform"> <input id="login_name" name="login_name" type="text" > <input id="login_password" name="login_password" type="text" > <input id="submit" type="submit"> </form>
I am trying to use AJAX to execute the PHP script and return the response. Here is what I have so far:
$(document).ready(function(){
$('#regform').on('submit', function(e) {
function response(response)
{
alert("The server says: " + response);
}
e.preventDefault();
var data = $(this).serialize();
$.ajax
({
type : 'POST',
url : '/?page=authenticate/register',
dataType : 'json',
data : data,
success : response(),
});
});
});
As far as I understand, I should be getting an alert box with the response. However, all I get isThe server says: undefined
So obviously AJAX is failing to make the call, and I cannot figure out why. Below is the XHR output:
XHR finished loading: POST "http://stronglinks.org/?page=authenticate/register"
.l.cors.b.crossDomain.send @ jquery.min.js:
4n.extend.ajax @ jquery.min.js:
4(anonymous function) @ (index):
216n.event.dispatch @ jquery.min.js:
3r.handle @ jquery.min.js:3
Can anyone help?