[英]stop javascript execution till jquery JSON response
I am calling a third party webservice using getJSON
callback. 我使用
getJSON
回调调用第三方Web服务。 The function does not have a success
handler attached to the function and since it is third party, I cannot edit the code also. 该函数没有附加到函数的
success
处理程序,因为它是第三方,我也无法编辑代码。 By the time I receive the response, some of the javascript function in the page already executes. 当我收到响应时,页面中的一些javascript函数已经执行。
Is there any way I can delay the execution of the Javascript function till I receive the response data from web service except setTimeout
method. 有什么办法可以延迟执行Javascript函数,直到我收到来自web服务的响应数据,除了
setTimeout
方法。
You can use jQuery's .ajaxStart()
and .ajaxComplete()
events to get noticed if your ajax call is running. 如果你的ajax调用正在运行,你可以使用jQuery的
.ajaxStart()
和.ajaxComplete()
事件来引起注意。 You can create a bool variable, something like isAjaxRunning
and put this around the other javascript. 你可以创建一个bool变量,比如
isAjaxRunning
并把它放在其他的javascript中。 So if isAjaxRunning
is true, dont execute other javascript. 因此,如果
isAjaxRunning
为true, isAjaxRunning
执行其他javascript。
if you have access to the code you can make it synchonize by adding the attribute 如果您有权访问代码,则可以通过添加属性使其同步
async : false
- then it won't be a asynchronous call like the normal ajax . async : false
- 然后它不会像普通的ajax那样是异步调用。
If you can post the sample code - that will give a clear picture. 如果您可以发布示例代码 - 这将给出清晰的图片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.