Asynchronous and synchronous

2019-09-21 16:13发布

IF I used synchronous and asynchronous ajax request on the same page when page will load on browser and synchronous request is first and asynchronous is second request on page. So what will be happen there?

  1. will Asynchronous request wait until synchronous request will get the data from the server.

  2. Or will Asynchronous request not wait and execute as the request?

I tried to find this answer but didn't get anywhere. Please give the answer if anyone have

2条回答
萌系小妹纸
2楼-- · 2019-09-21 16:54

Synchronous means that the code that initiates the synchronous requests waits and blocks until the request completes. The calling and the called code are "in sync". Asynchronous means the code that initiates the request continues immediately and the asynchronous call will complete sometime later. The calling and the called code are "not in sync" or asynchronous.

As such, if your code fires a synchronous request, it waits until that request is completed. Nothing else will happen in the meantime, so the asynchronous request won't be triggered until the synchronous one completes.

If you fire the asynchronous request first and the synchronous one afterwards, it's not necessarily clear which code will finish/execute first, since the asynchronous request may finish at any time.

查看更多
Ridiculous、
3楼-- · 2019-09-21 17:09

The asynchronous will take place when your synchronous request is done. So number 1.

查看更多
登录 后发表回答