Sending an ajax request to a php file:
$.ajax({ url: '/engine/search.php', dataType: 'json', data: { data:data }, method: 'POST', success: function(){ console.log('Request sent successfully. Pending...') } }).fail(function(response){ console.log(response); }).done(function(){ console.log('OK'); // "OK" не выводится }); PHP:
<?php require('functions.php'); if(isAjax()) { $data = $_POST['data']; if(isset($data) && !empty($data)) { if(!preg_match('/[AZ][AZ][AZ]/', $data['from']) && !preg_match('/[AZ][AZ][AZ]/', $data['to'])) { header('HTTP/1.0 500 Internal Server Error'); die('Bad IATA codes provided'); } if(!validateDate($data['there']) && !validateDate($data['thence'])) { header('HTTP/1.0 500 Internal Server Error'); die('Bad date format provided'); } if(!preg_match('/^[1-9]*$/', $data['adults']) && !preg_match('/^[0-9]*$/', $data['teens']) && !preg_match('/^[0-9]*$/', $data['kids'])) { header('HTTP/1.0 500 Internal Server Error'); die('Bad passengers data provided'); } session_start(); $_SESSION['search_data'] = json_encode($data); } } else { header('HTTP/1.0 403 Forbidden'); die('Access denied'); } ?> It successfully processes the received data, but for some reason the ajax request comes in fail (), although the code is 200 (OK). What could be the problem?
done()andfail()in js and transfer that code tosuccess,errorandcompletecallbacks. There, the matter is thatsuccessis an analogue of the samedone(), and it is possible if the framework code sees that it has passed handlers in the settings array, it will go along the way of processing there, thus ignoring the handlers that you hung after the point. - Stanislav Belichenko Februarydone()and so on. - Stanislav Belichenko