I am using ajax to post a form to my localproxy which then posts to affiliate client and also my database. However it keeps either not posting using ajax or coming up with an error. I used this exact code format on other sites without a problem.
my ajax code
$(document).ready(function(){
// ajax code start
$('#form').on('submit', function (e){
e.preventDefault();
$.ajax({
type: "POST",
url: "/localProxy.php",
data: $('#form').serialize(),
success: function (response) {
document.location = '/thank-you';
// do something!
},
error: function () {
alert('There was a problem!'); // handle error
}
});
});
And here is my current form header and submit code
<form id="form" name="form" >
<input type="submit" name="submit" id="submit" value="Enter" />
Either the default submit activates bypassing the ajax or the alert message comes up.
Make sure you have no error in your
localProxyscript or it does exist. I also noticed you have a missing function enclosure in your code: