下面的jquery的ajax()提交表单,表单数据成功保存到数据库,谷歌调试器的preview和response标签没有json错误信息,控制台也没有显示错误信息,但为什么会执行fail()里面的alert,而done()里面的跳转和alert不会执行?
$(function () {
//...
$(document).on('submit', '#formProfile', function (e) {
e.preventDefault();
$("#submitProfile").addClass('disabled');
$('#formProfile span>strong').text('');
$('fieldset span').parent().parent().removeClass('has-danger');
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: "{{ url('user/profile/') }}",
dataType: 'json',
processData: false,
contentType: false,
cache: false,
data: formData
})
.done(function (data) {
alert('success');
location.href = "../articles/create";
})
.fail(function () {
//console.log(data);
alert('The server failed somewhere');
$("#submitProfile").removeClass('disabled');
});
});
})
</script>
下面是在fail()中console.log(data)打印的内容截图:
跟跨域有关么?跳转到的文件所在目录和本文件所在目录不属于同一个父目录,但属于同一个父父目录,这算跨域么?
dataType指定返回
json
格式的数据内容看下控制台返回的数据结构符不符合格式要求
看到
responseText
为空