Отправляю запрос в базу, кликаю на кнопку сохранить отрабатывает beforeSend лоадер, и запись в базу доходит и записывается, но сам ajax возвращает error, следовательно success не выполняется. Данные в базу пишутся. В чем может быть проблема?????
$('#form_update').on('click', '#button_update', function(){
var category = $('input#category_edit').val();
var is_active = $('select#status').val();
var title = $('input#title').val();
var description = $('textarea#description').val();
var status;
if(is_active == 1) {
status = "Отключено";
}else{
status ="Включено";
}
$.ajax({
url: "/admin/categories/update",
type: "post",
beforeSend: function(){
var bodyH = $(window).height() / 2;
$("div#edit_cat").after('<div id="system-load" style="position:fixed;'
+ 'top:0px; left:600px; width:10%; height:10%;'
+ 'z-index:99999999; color:#fff; padding-top:' + bodyH + 'px;"'
+ 'align="center">'
+ '<img src="/images/preloader.gif"'
+ ' alt="Пожалуйста, подождите..." /></div>');
$(window).bind('load', function() {
$('#system-loading').fadeOut('slow').remove();
$('#sytem-content').animate({opacity: 1}, 'fast');
});
},
dataType: 'json',
data: {
'id':item_id,
'_token':csrf,
'category':category,
'is_active':is_active,
'title':title,
'description':description,
},
succces: function(data){
alert("Ajax запрос выполнен\n"+data.message);
$("tr#"+item_id+"> td[class=cat]").text(category);
$("tr#"+item_id+"> td[class=status]").text(status);
$("#system-load").remove();
},
error: function(xhr,status,error){
alert('Ошибка Ajax-запроса\n'+status+'\n'+error);
console.log(status);
console.log(error);
}
});
return false;
});
У вас есть в $.ajax() параметр dataType: 'json'. Вот что о нем написано в документации:
dataType (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the
server. If none is specified, jQuery will try to infer it based on the
MIME type of the response (an XML MIME type will yield XML, in 1.4
JSON will yield a JavaScript object, in 1.4 script will execute the
script, and anything else will be returned as a string).
То есть, если вы указали json, то и вернуть должны строго его. Вы же, судя по всему, считаете, что этот параметр обозначает не то, что сервер должен вернуть, а то, что вы ему передаете. Но это не так :)
Ну и еще, надо писать не succces, а succcess.
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости