Основы использования .ajax будет выглядеть примерно так:
HTML
<form id="foo">
<label for="bar">A bar</label>
<input id="bar" name="bar" type="text" value="" />
<input type="submit" value="Send" />
</form>
<!-- The result of the search will be rendered inside this div -->
<div id="result"></div>
JavaScript
/* Attach a submit handler to the form */
$("#foo").submit(function(event) {
/* Stop form from submitting normally */
event.preventDefault();
/* Clear result div*/
$("#result").html('');
/* Get some values from elements on the page: */
var values = $(this).serialize();
/* Send the data using post and put the results in a div */
$.ajax({
url: "test.php",
type: "post",
data: values,
success: function(){
alert("success");
$("#result").html('Submitted successfully');
},
error:function(){
alert("failure");
$("#result").html('There is error while submit');
}
});
});
В чем проблема? Ответ на ваш вопрос ... Чтобы управлять ошибками, используйте вместо этого '$ .ajax'. Существует уже много ответов в Интернете .......... – JoDev
вам не хватает открывающей фигурной скобки '... '). Serialize(), function()' <--- здесь – Novocaine
@JoDev OP также может использовать ['.fail()'] (http://api.jquery.com/deferred.fail/) как часть обратного вызова отложенного объекта. – War10ck