Tag: 单线程

如果Javascript不是multithreading的,有没有理由实现异步Ajax队列?

我的php服务器有问题(我的电脑是唯一的连接)。 我最初认为部分原因是因为太多的ajax请求(我有一个脚本,每次击键执行一个ajax请求)所以我实现了一个设计来控制ajax请求流入队列。 以下是我的代码: //global vars: activeAjaxThread = 0; //var describing ajax thread state ajaxQue = []; //array of ajax request objects in queue to be fired after the completion of the previous request function queRequest(ajaxObj) { ajaxQue.push(ajaxObj); if (activeAjaxThread == 0) { fireOffAjaxQue(); } else { return ‘ajax thread is running’; } } function fireOffAjaxQue […]