JavaScript .execute命令是否可以同步运行,或者转换为Ajax ?

Can a JavaScript .execute command be run synchronously, or converted to Ajax?

本文关键字:或者 转换 Ajax 运行 同步 命令 execute 是否 JavaScript      更新时间:2023-09-26

我使用的是Javascript的ArcGIS API: http://help.arcgis.com/en/webapi/javascript/arcgis/index.html

这段JavaScript似乎是异步运行的,是否有可能使其同步运行,或者甚至将其转换为同步Ajax ?

我似乎找不到太多关于。execute命令的信息

我需要它同步运行,以便PHP可以抓取结果(最终结果将返回true或false, alert只是用于调试)

var identifyTask = new esri.tasks.IdentifyTask("http://website.here");
var identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 0;
identifyParams.returnGeometry = true;
identifyParams.layerIds = [layerID];
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.geometry = geom;
identifyParams.mapExtent = map.extent;
identifyTask.execute(identifyParams, function(results) {
    if (results.length == 0) {
        alert('true');
    } else {
        alert('false');
    }
});

API规范这里不包括同步执行的规范。

只适用于回调和onCompleteonError事件。

execute()方法不是Javascript标准库的一部分。请注意在示例代码中如何开始使用esri。您正在使用esri的库。快速谷歌搜索"esri javascript"找到了API网站,然后浏览API找到了你在代码中使用的内容。

至于您说希望PHP抓取结果,这没有多大意义。这个javascript被设计为运行客户端,而PHP是一个服务器端技术。请进一步详细说明PHP将如何抓取结果,以及为什么这个方法是同步的将对这有任何影响。