将jquery ajax转换为本机javasctipts [英] convert the jquery ajax to native javasctipts

查看:70
本文介绍了将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);

                }

推荐答案

.ajax(attributes);
}
.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);

                }


这篇关于将jquery ajax转换为本机javasctipts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆