Запрос Ajax с JQuery на странице разгружается

По моему опыту, это была вещь соглашения. Я не знаю ни о какой технической причине для использования интервала по Int32, но это:

  1. Более быстрый для ввода.
  2. более знакомый типичному разработчику C#.
  3. А различный цвет в подсветке синтаксиса Visual Studio по умолчанию.

я особенно люблю тот последний.:)

68
задан tshepang 8 April 2014 в 19:03
поделиться

4 ответа

I believe you need to make the request synchronous instead (it's asynchronous by default) using the async : false parameter.

Synchronous requests lock up the browser until they complete. If the request is asynchronous, the page just keeps on unloading. It's quick enough that the request never even has time to fire off.

77
ответ дан 24 November 2019 в 14:17
поделиться

Try calling it with async = false;

jQuery.ajax({url:"http://localhost:8888/test.php?", async:false})

I just tried it.

20
ответ дан 24 November 2019 в 14:17
поделиться

Maybe you'd have more success using the onbeforeunload event instead?

   $(window).bind('beforeunload', ...
1
ответ дан 24 November 2019 в 14:17
поделиться

Your function and Ajax call look fine, so my guess is that your browser window is closed before ajax call has time to go to the server and back. The ajax call might return something when the window is closing, try adding error function to your ajax call to see if that's the case:

error: function (xhr, textStatus) {
    alert('Server error: '+ textStatus);
}
0
ответ дан 24 November 2019 в 14:17
поделиться
Другие вопросы по тегам:

Похожие вопросы: