In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
这篇文章主要介绍"async属于ajax的属性吗"的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇"async属于ajax的属性吗"文章能帮助大家解决问题。
async是ajax的属性。async属性用于规定ajax请求是否异步处理,默认值是true(异步处理);ajax执行后,会继续执行后面的的脚本,直到服务端返回数据后,触发ajax里的成功回调函数success,这时候执行的是两个线程。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
async是ajax的属性。
async属性用于规定ajax请求是否异步处理,值是布尔类型,默认值是true(异步处理)。
$.ajax async:true 或者 false的作用
在写 ajax 请求的时候默认不写 async 这个属性,async 默认为 true,即异步方式。ajax 执行后,会继续执行后面的的脚本,直到服务端返回数据后,触发 ajax 里的成功回调函数 success,这时候执行的是两个线程。
若将 async 设为 false,则请求为 同步请求,在服务端没有返回数据之前,不会执行 ajax 后面的脚本,只有当 ajax 请求完成,才会继续执行 ajax 后面的脚本。
示例:
var App = function () { this.Startup = function () { this.Test(); }; this.Test = function () { var name = null; $.ajax({ type: 'POST', url: '/Home/GetName', // 本地测试接口 async: true, success: function (result) { name = result.name; } }); alert(name); };};$(document).ready(function () { var app = new App(); app.Startup();});
① 当 async:true的时候,异步请求,会继续执行 ajax 后面的脚本,所以会执行 alert
② When async:false, the synchronization request will wait for Ajax execution to complete before executing the script behind it, so name will be assigned in the Ajax success callback function success.
The content of "async belongs to the attributes of Ajax" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.