AJAX调用是否没有阻塞,它们的生命周期是什么?

时间:2022-12-06 10:40:52

I feel ackward asking these fundamental questions given that I am not exactly new to web development. But I want to double-check my assumptions nevertheless...

考虑到我对web开发并不陌生,我觉得问这些基本的问题有点困难。但是我想再次验证一下我的假设……

I'm building the recording of unique image views in my application. When a user (not a bot) visits an image page, an Ajax call is made to a back-end process that collects the session info, compares for duplications and stores the visit. I have all my javascript references as well as this call at the bottom of the HTML, just before the </body> element:

我正在我的应用程序中构建独特的图像视图记录。当用户(而不是机器人)访问图像页面时,将对后端进程进行Ajax调用,该进程收集会话信息,比较副本并存储访问。我有我所有的javascript引用以及这个在HTML底部的调用,就在元素之前:

$.get(basepath + "image/1329/record/human", function(data){
console.log("Data Loaded: " + data);
});

By default, the call to $.get is made asynchronous. Yet I want to test the following assumptions:

默认情况下,调用$。得到的是异步的。但我想检验以下假设:

  • Is it correct that this method ensures that the call to the view recording script is non-blocking for the rest of the UI?
  • 这个方法可以确保对视图记录脚本的调用对UI的其余部分是无阻塞的吗?
  • Is it correct that the back-end script will finish once called, regardless of whether the user navigates to another page?
  • 无论用户是否导航到另一个页面,后端脚本一旦调用就会结束,这是正确的吗?

3 个解决方案

#1


5  

According to jQuery .get reference...

根据jQuery,获取参考…

This [$.get()] is a shorthand Ajax function, which is equivalent to:

这个[$.get()]是一个简单的Ajax函数,相当于:

$.ajax({ url: url,   data: data,  
         success: success,   dataType: dataType
});

And $.ajax is asynchronous (i.e. non-blocking) by default, that's what the A in Ajax means.

和美元。默认情况下,ajax是异步的(即非阻塞),这就是ajax中的A的含义。

Also, back-end server code is started in the moment the server receives the request and then runs independently of the client staying on the page or not, unless you implement some kind of mechanism to stop the running service which I suppose you did not.

而且,后端服务器代码是在服务器接收请求的那一刻启动的,然后独立地运行,而客户机是否驻留在页面上,除非您实现某种机制来停止正在运行的服务(我认为您没有实现这种机制)。

God bless!

上帝保佑!

#2


4  

The jQuery.get request you're making is asynchronous and will not block the DOM or other JavaScript from continuing. The get function is a shorthand method which uses jQuery.ajax.

jQuery。您正在进行的get请求是异步的,不会阻止DOM或其他JavaScript的继续。get函数是一种使用jQuery.ajax的简写方法。

The second question I don't have a solid answer for -- I expect it may depend more on how the back-end code is structured and whether it's told that the session/request has terminated.

第二个问题我没有一个可靠的答案——我希望它更多地取决于后端代码的结构,以及它是否被告知会话/请求已经终止。

API:

API:

#3


2  

that is correct on both counts

这两点都是正确的。

#1


5  

According to jQuery .get reference...

根据jQuery,获取参考…

This [$.get()] is a shorthand Ajax function, which is equivalent to:

这个[$.get()]是一个简单的Ajax函数,相当于:

$.ajax({ url: url,   data: data,  
         success: success,   dataType: dataType
});

And $.ajax is asynchronous (i.e. non-blocking) by default, that's what the A in Ajax means.

和美元。默认情况下,ajax是异步的(即非阻塞),这就是ajax中的A的含义。

Also, back-end server code is started in the moment the server receives the request and then runs independently of the client staying on the page or not, unless you implement some kind of mechanism to stop the running service which I suppose you did not.

而且,后端服务器代码是在服务器接收请求的那一刻启动的,然后独立地运行,而客户机是否驻留在页面上,除非您实现某种机制来停止正在运行的服务(我认为您没有实现这种机制)。

God bless!

上帝保佑!

#2


4  

The jQuery.get request you're making is asynchronous and will not block the DOM or other JavaScript from continuing. The get function is a shorthand method which uses jQuery.ajax.

jQuery。您正在进行的get请求是异步的,不会阻止DOM或其他JavaScript的继续。get函数是一种使用jQuery.ajax的简写方法。

The second question I don't have a solid answer for -- I expect it may depend more on how the back-end code is structured and whether it's told that the session/request has terminated.

第二个问题我没有一个可靠的答案——我希望它更多地取决于后端代码的结构,以及它是否被告知会话/请求已经终止。

API:

API:

#3


2  

that is correct on both counts

这两点都是正确的。