Home > Web Front-end > JS Tutorial > body text

Solution to page flickering caused by asynchronous request based on JQuery's $.ajax method_jquery

WBOY
Release: 2016-05-16 09:00:06
Original
3983 people have browsed it

scenario

currently, there is a need to fill in the content in the text box and automatically trigger the keyup event. the drop-down list will automatically filter the corresponding options. however, after using $,ajax, i found that every time the event is triggered, the entire web page will flash. global ajax event triggered

code snippet

$.ajax({ 
type: "POST", 
url: root + "/xxx, 
data: requestData, 
dataType: "json", 
success: function(data){ 
// 清空列表 
$("#formOpinion #listLeft").empty(); 
$.each(data, 
function(i, $data) { 
var $option = $("<option name='opinion.tag' value=" 
+ $data.code + $data.name + ">" + $data.code 
+ $data.name + "</option>"); 
// 绑定数据到listLeft 
$("#formOpinion #listLeft").append($option); 
}); 
} 
}); 
Copy after login

solution

looking at the jquery api documentation, we found that there is a global property in $.ajax that can set whether the ajax event is global. the default is true, change it to false




the above content is the solution introduced by the editor to solve the problem of page flickering caused by asynchronous requests based on jquery's $.ajax method. i hope it will be helpful to everyone!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!