简体   繁体   English

Microsoft Edge 和 ajax 计时

[英]Microsoft Edge and ajax timing

I have code with an ajax request that has been running fine for over two years but fails intermittently in Microsoft Edge.我有一个 ajax 请求的代码,该请求已经运行了两年多,但在 Microsoft Edge 中间歇性失败。

set_page : function()
{
    $.ajax(
    {
        type: 'POST',
        url: '/ajax/set_page',
        dataType: 'json',
        data: {'book_id' : this.book_id, 'page' : this.page},
    });
},

ajax/set_page is a php function that updates the column 'page' in the book table. ajax/set_page 是一个 php 函数,用于更新 book 表中的“page”列。

When I debug the code in Chrome, the database is updated as soon as I step over the $.ajax call.当我在 Chrome 中调试代码时,只要我跳过 $.ajax 调用,数据库就会更新。 In Edge, the database is not updated until the program thread in javascript is finished.在 Edge 中,直到 javascript 中的程序线程完成后才会更新数据库。

set_page {
-----------> Chrome db -> page = 11, Edge db -> page = 11
   $.ajax({...POST}); 
-----------> Chrome db -> page = 12, Edge db -> page = 11
};
};
};
----------> Edge db -> page = 12, ajax success!

Usually that is not a problem but occasionally the thread has a lot of extra processing and when the ajax/set_page php function is finally called, the $_POST values are null.通常这不是问题,但偶尔线程有很多额外的处理,当最终调用 ajax/set_page php 函数时,$_POST 值为空。

Has anybody else seen this sort of behavior in Edge?有没有其他人在 Edge 中看到过这种行为? Is there any way to kick off the ajax request so it calls my php function right away?有什么方法可以启动 ajax 请求,以便它立即调用我的 php 函数?

Maybe my question should be: Why are my $_POST variables sometimes null in my ajax call in Edge?也许我的问题应该是:为什么我的 $_POST 变量有时在 Edge 的 ajax 调用中为空? Is there some way to debug them between the $.ajax call and my php function?有什么方法可以在 $.ajax 调用和我的 php 函数之间调试它们吗? .................... ………………

After more debugging, a page reload that happens in IE11 (to fix a flash/IE11 bug) is causing the problem.经过更多调试后,IE11 中发生的页面重新加载(修复 Flash/IE11 错误)导致了问题。

set_page {
-----------> Chrome db -> page = 11, Edge db -> page = 11
   $.ajax({...POST}); 
-----------> Chrome db -> page = 12, Edge db -> page = 11
};
};
if last_page
   do stuff
   if IE11
     location.reload()
};
----------> 
not last page: Edge db -> page = 12, ajax success!
last page: Edge db -> page = null, book_id = null

So I have two issues:所以我有两个问题:

  1. it looks like when the page is reloaded, the POST parameters are cleaned up but the ajax request is still executed.看起来页面重新加载时,POST参数被清除,但ajax请求仍在执行。

  2. the Edge browser is being identified as IE11. Edge 浏览器被识别为 IE11。

It looks like the IE11/flash bug was fixed in Edge so I should be able to remove the reload but I need to do some more testing to make sure.看起来 IE11/flash 错误已在 Edge 中修复,因此我应该能够删除重新加载,但我需要进行更多测试以确保。

your ajax call is asynchronous, so the function runs (hits your breakpoint in your dev tools) but that doesn't mean that it has sent the data to your backed and received a response back that the operation completed.您的 ajax 调用是异步的,因此该函数会运行(在您的开发工具中命中您的断点),但这并不意味着它已将数据发送到您的后台并收到操作完成的响应。

set_page : function()
{
    $.ajax(
    {
        type: 'POST',
        url: '/ajax/set_page',
        dataType: 'json',
        data: {'book_id' : this.book_id, 'page' : this.page},
        success: function(data){
            console.log('the page was set');
        }/* make sure there is no trailing comma*/
    });
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM