简体   繁体   English

Javascript 应用程序中的同步执行

[英]Synchronous Execution in Javascript app

I'm writing a js app that is tracking movement of devices.我正在编写一个跟踪设备移动的 js 应用程序。 The user is able to select from a list of devices which ones to track on a map.用户可以从设备列表中选择要在地图上跟踪的设备。 The displayed device ID is different than the ID reported by the device to the tracking database, so I need to do a lookup of displayed device ID to actual device ID.显示的设备 ID 与设备向跟踪数据库报告的 ID 不同,因此我需要将显示的设备 ID 与实际设备 ID 进行查找。

I'm using ajax to query the database, but I need it function synchronously, the app needs to wait until the actual device IDs are returned until it then starts to track location by those IDs.我正在使用 ajax 查询数据库,但我需要它同步运行,应用程序需要等到实际设备 ID 返回,然后才开始通过这些 ID 跟踪位置。 I know we're not supposed to make ajax calls with async set to false, and I haven't been able to get wait/async to function where execution is blocked until the device IDs are returned in the ajax.done callback.我知道我们不应该在 async 设置为 false 的情况下进行 ajax 调用,并且在 ajax.done 回调中返回设备 ID 之前,我无法在执行被阻止的情况下获得等待/异步功能。

What is the best practice for this situation?这种情况的最佳做法是什么?

Thanks...谢谢...

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

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