Answer the question
In order to leave comments, you need to log in
JS does not work, gives an error in the browser?
Browser error
VM7348:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0
at Function.parse [as parseJSON] (<anonymous>)
at Object.success ((index):171)
at u (jquery.min.js:1)
at Object.fireWith [as resolveWith] (jquery.min.js:1)
at k (jquery.min.js:1)
at XMLHttpRequest.<anonymous> (jquery.min.js:1)
$(document).ready(function() {
$("form").submit(function(event) {
event.preventDefault();
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(result) {
json = jQuery.parseJSON(result);
if (json.url) setTimeout(redirect, 2000, json.url);
swal({
title: json.header,
text: json.message,
icon: json.status,
});
}
});
});
});
function redirect(url) {
window.location.href = url;
}
Answer the question
In order to leave comments, you need to log in
Обычно если полученный с сервера JSON начинается с символа "<", это означает, что сервер вместо него возвращает HTML-код (вероятнее всего, страницу об ошибке). Смотрите, что конкретно сервер вам возвращает на данный запрос, который вы получаете AJAX'ом.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question