1

Below is the code which is being used to make a request to an AJAX service, it currently works in chrome without any issues but fails with out any status's or error codes.

AJAX request not working correctly

AJAX Resource panel

Response is set in the controller for the request

return response()->json(['hello' => $value])->setStatusCode(Response::HTTP_OK, Response::$statusTexts[Response::HTTP_OK]);

< script type = "text/javascript" >

  var startTime = new Date().getTime();
$.ajaxSetup({
  headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});


$(window).on('beforeunload ', function() {
  doLeavingAjax();
});

var currentPage = window.location.pathname;
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');

function doLeavingAjax() {
  var endTime = new Date().getTime();
  var timeSpent = endTime - startTime;
  var i = 0;

  $.ajax({
    url: '/PSTracking/leave',
    method: 'POST',
    dataType: 'json',
    async: 'false',
    data: JSON.stringify({
      "timeSpent": timeSpent
    }),
    contentType: "application/json; charset=utf-8",
    beforeSend: function(xhr) {
      xhr.setRequestHeader("_token", CSRF_TOKEN);
    }

  });
  return false;

}

<
/script>
D.Mercer
  • 11
  • 2
  • Is the call making it to the backend at all? – Samsquanch Mar 07 '17 at 16:43
  • @Samsquanch in chrome it shows in the logs but it doesn't even hit the log in safari. – D.Mercer Mar 08 '17 at 08:53
  • If you change `async: 'false',` to `async: false,`, does that change anything? Your issue looks similar to [this one](http://stackoverflow.com/questions/5548505/post-call-is-not-happening-in-safari). – Samsquanch Mar 08 '17 at 13:25

0 Answers0