本文介绍了将jquery ajax转换为本机javasctipts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,我想将其转换为原生javascripts
这里是ajaxHandler函数代码
here is my code and i want to convert it to native javascripts
here is ajaxHandler function code
ajaxHandler = {
defaultAttributes: {
type: 'GET',
url: 'index.php/request',
datatype: 'json',
data: {},
success: null,
error: function(data) {
errorHandler.showError('An Error occurred while trying to retreive your requested data, Please try again...');
},
timeout: function() {
errorHandler.showError('The request has been timed out, Please check your Internet connection and try again...');
}
},
sendRequest: function(attributes) {
Paper.giffyLoading.style.display = 'block';
// Program.status('Generating Network Request...');
if (!attributes.nopopup) {
if (attributes.loadmsg) {
Controllers.AnimationController.createProgressBarScreen(attributes.loadmsg);
attributes.loadmsg = null;
}
// else
// Interfaces.AdvancePopup.createModalPopupLoadingDiv();
}
$.ajax(attributes);
}
我尝试将其更改为原生javasctipts
my attempt to change it to native javasctipts
XMLRequestDefaultHandler = function () {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', 'index.php/request', true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 || xmlHttp.status === 200) {
} else {
errorHandler.showError('An Error occurred while trying to retreive your requested data, Please try again...');
}
return;
};
xmlHttp.send(null);
}
推荐答案
我尝试将其更改为原生javasctipts
my attempt to change it to native javasctipts
XMLRequestDefaultHandler = function () {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', 'index.php/request', true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState === 4 || xmlHttp.status === 200) {
} else {
errorHandler.showError('An Error occurred while trying to retreive your requested data, Please try again...');
}
return;
};
xmlHttp.send(null);
}
这篇关于将jquery ajax转换为本机javasctipts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!