Is it possible to set async: false
when calling $.getJSON()
so that the call blocks rather than being asynchronous?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
In my case, Jay D is right. I have to add this before the call.
In my previous code, I have this:
It works find. Then I change to
The alert is undefined.
If I add those three lines, the alert shows the data again.
I don't think you can set that option there. You will have to use jQuery.ajax() with the appropriate parameters (basically getJSON just wraps that call into an easier API, as well).
Both answers are wrong. You can. You need to call
before your json ajax call. And you can set it to true after call retuns ( if there are other usages of ajax on page if you want them async )
If you just need to
await
to avoid nesting code:You need to make the call using
$.ajax()
to it synchronously, like this:This would match currently using
$.getJSON()
like this:I think you both are right. The later answer works fine but its like setting a global option so you have to do the following: