我有這個AJAX請求連接到newsletter-signup.html
文件,然後搜索返回的data
變量字符串「form-success」。 此字符串通過if
語句中的(Django)模板應用,以標記表單已成功。Javascript/jQuery:如何讓這個AJAX請求運行得更快?
下面是搜索整個數據片段:
if (data.indexOf('form-success') > 0) {
有搜索該數據更快的方法?或者,也許althoteger更好的方式來確定返回的數據是否成功註冊?
在此先感謝您的幫助。下面是完整的代碼:
$.ajax({ url: '/newsletter-signup', type: 'GET', data: {email: emailVal}, async: false,
success: function(data){
// Returning 'form-success' in our data string indicates the sign up worked
if (data.indexOf('form-success') > 0) {
// open the success message in a modal window
happyModal.open({ content: thankYouContent });
} else {
// if not successful re-load the contents, firing our standard error message
theBtn.removeClass('disabled');
$('.login-panel').load('/newsletter-signup','email=' + encodeURIComponent(emailVal), function() {
});
}
}
});
在請求正在製作時顯示一個小的加載圖形。我非常懷疑是否還有其他方法可以使UI更快。 –