问题
My form properly submits data via POST utilizing Ajax. However I am trying to redirect the user upon successful submission. The problem is, even though the form successfully submits, instead of redirecting the user it displays an error. According to firebug the page I am submitting to, is throwing up a 200 success code. I am using jquery 1.8.3.
My Code:
$(document).ready(function() {
$("#form4").submit(function(e) {
e.preventDefault();
var frm = $('#form4');
$.ajax({
type: 'POST',
url: 'http://requestb.in',
data: frm.serialize(),
success : function() {
window.location = "http://www.google.com";
},
/*error : function() {
alert("Something went bad");
}*/
});
});
Here is my form HTML:
<form action="" method="post" id="form4" name="form4" enctype="multipart/form-data">
<input id="name" name="name" type="text" tabindex="1" value="Insert your name" class="required">
<input id="email" name="email" type="text" tabindex="2" value="Insert your e-mail" class="required email">
<input id="phone" name="phone" type="text" tabindex="3" value="Insert your phone number">
<input type="submit" name="submit_button" value="Try it free">
</form>
In an attempt to figure out the exact error, I added the following code to the top of my script, which I found from this POST:
$(function() {
$.ajaxSetup({
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
});
After adding that code, that following error I get is from the first error code check: 'Not connect.\n Verify Network.'. I tested this is both firefox and Chrome with same results.
Edit: Additional information
I am trying to post the data from my website to a 3rd party form processor service which accepts post, get, and put commands. The service is zapier.com and requestb.in is a service I am using to troubleshoot my form submissions.
来源:https://stackoverflow.com/questions/18743487/successful-ajax-post-displays-error-message