@mrzgt

Почему получаю ошибку Uncaught (in promise) SyntaxError: expected expression, got <?

async function fastOrder($product_id) {
    let overlay = document.createElement("section");
$(overlay).addClass("fastorder-custf");
    $('body').prepend(overlay);
    let loading = document.createElement("div")
    overlay.prepend(loading)
    loading.innerHTML += "<i class=\'fa fa-spinner fa-pulse overlay__icon \' aria-hidden=\'true\'></i>";
  //  $(".mfp-close").trigger('click');
    let response = await fetch('index.php?route=order/getForm', {
        method: 'POST',
        headers: {
           // 'Content-Type': 'application/json;charset=utf-8'
        },
        body: JSON.stringify($product_id),
    }).then(response => {
        return response.json();
    }).then(html => {
        $(loading).after(html);
    });
}


PHP
$data = json_decode(file_get_contents("php://input"), true);
  • Вопрос задан
  • 177 просмотров
Пригласить эксперта
Ответы на вопрос 1
@zkrvndm
Софт для автоматизации
Перепишите код свой, у вас jQuery в вперемешку с обычным кодом идет, обычно так не делают.

function fastOrder(product_id) {
	
	$('body').prepend(`<section class="fastorder-custf">
		<div class="ajax_result">
			<i class="fa fa-spinner fa-pulse overlay__icon" aria-hidden="true"></i>
		</div>
	</section>`);
	
	$('.mfp-close').trigger('click');
	
	$.ajax({
		url: 'index.php?route=order/getForm',
		type: 'POST',
		contentType: 'application/json; charset=UTF-8',
		data: product_id,
		dataType: 'html',
		success: function(response) {
			$('.ajax_result').html('Ответ сервера: ' + response);
		},
		error: function(xhr, status) {
			$('.ajax_result').html('При отправке запроса произошла ошибка, детали см. в консоли');
			console.log('При отправке запроса произошла ошибка:');
			console.dir(xhr);
		}
	});
	
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы