我目前正在做的是使用 jQuery 在每次按键时执行 ajax 请求。因此,如果我的用户输入 d-o-n-k-e-y,它将为每个字母发送一个请求。但是,由于它们在网络上采用不同的路径到达服务器,因此如果它们输入 d-o-n-k-e-y 的速度太快,它们并不总是按顺序到达。他们可能会以 D-n-o-k-y-e 的形式到达,并做出相应的 react 。有没有一种好方法可以确保所有请求按顺序发送?
我认为在发送下一个请求之前等待请求的确认是行不通的,因为这会大大减慢信息传输速度。有人有什么想法吗?
谢谢。
最佳答案
来自:http://api.jquery.com/jQuery.ajax/
异步 bool 值
默认值: true
By default, all requests are sent asynchronous (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.
此外,每次击键都发送 ajax 请求可能不是最好的主意。您不能使用超时并发送 don
和 key
请求(例如每 300 毫秒缓冲一次)吗?
关于php - 有没有办法让ajax请求始终按顺序进行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3747469/