Jenson
Jenson
  • 发布:2015-03-05 15:00
  • 更新:2015-11-19 09:55
  • 阅读:4241

ajax errorThrown提示未经授权

分类:MUI
mui.ajax('https://192.168.100.111/api/',{  
        dataType:'json',  
        type:'get',  
        timeout:10000,           
        success:function(data){  
            alert("ajax ok");  
        },  
        error:function(xhr,type,errorThrown){  
            mui.alert(errorThrown,'提示');  
        }  
    });

直接进入error方法,提示未经授权,也没有请求,但是换成本地的json文件ajax是success的

mui.ajax('js/data.json',{  
        dataType:'json',  
        type:'get',  
        timeout:10000,            
        success:function(data){  
            alert("ajax ok");  
        },  
        error:function(xhr,type,errorThrown){  
            mui.alert(errorThrown,'提示');  
        }  
    });

请问是何解?

2015-03-05 15:00 负责人:无 分享
已邀请:
Jenson

Jenson (作者)

问题解决了 是https的问题~

  • 张静

    请问你的https有什么问题,我也遇到了这样的问题

    2015-11-10 14:32

DCloud_UNI_FXY

DCloud_UNI_FXY

你是怎么测试的?真机联调?直接用浏览器访问你的这个地址返回是否正常?

  • 张静

    我这边也遇到了使用htpps地址ajax调用无效,使用本地地址或者http地址就可以执行的问题。请问这个问题应该怎么解决

    2015-11-10 14:33

  • DCloud_UNI_FXY

    回复 张静:打印错误信息

    2015-11-11 15:07

云钦

云钦 - 学习中

怎么解决的说一下啊,最恨这种人了,有问题提问,最后直接来一句问题解决,然后闪人

  • Jenson (作者)

    把https改成http就可以了

    2015-03-26 13:42

张静

张静 - web前端

(function($, doc) {
$.init();
$.plusReady(function() {
// plus.nativeUI.toast(txt);
//成功响应的回调函数
var respnoseEl = document.getElementById("response");
var success = function(response) {
var dataType = 'json';
if (dataType === 'json') {
response = JSON.stringify(response);
} else if (dataType === 'xml') {
response = new XMLSerializer().serializeToString(response).replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
respnoseEl.innerHTML = response;
};
//设置全局beforeSend
$.ajaxSettings.beforeSend = function(xhr, setting) {
//beforeSend演示,也可在$.ajax({beforeSend:function(){}})中设置单个Ajax的beforeSend
console.log('beforeSend:::' + JSON.stringify(setting));
};
//设置全局complete
$.ajaxSettings.complete = function(xhr, status) {
console.log('complete:::' + status);
console.log('complete:::' + xhr);
}

        var ajax = function() {  
            //利用RunJS的Echo Ajax功能测试  
            //var url = 'http://runjs.cn/action/echo/json';  
            //var url='http://221.234.36.202:36059//WebAPI/HomePage.ashx';  
            var url = 'https://192.168.100.58:8443/qilianbao/control/testAppAjax';  
            //请求方式,默认为Get;  
            var type = 'get';  
            //预期服务器范围的数据类型  
            var dataType = 'json';  
            //发送数据  
            var data = {  
                /*  name: "mui",  
                    version: "pre-release",  
                    author: "chb",  
                    description: "最接近原生APP体验的高性能前端框架"*/  
                account: "11",  
                password: "111",  
                phone: "111",  
                name: "aaa"  
            };  
            //url = url + (dataType === 'html' ? 'text' : dataType);  
            respnoseEl.innerHTML = '正在请求中...';  
            $.ajax(url, {  
                dataType: 'json',  
                type: 'post',  
                timeout: 20000,  
                success: function(data) {  
                    //var   response = JSON.stringify(data);  
                    //alert(data.data.jsondata.length);  
                    alert(JSON.stringify(data.data.jsondata[0].token));  
                    //alert(111);  
                },  
                error: function(xhr, type, errorThrown) {  
                    $.alert(errorThrown, '提示');  
                }  
            });  
            //$.getJSON(url, data, success);  
            /*  if (type === 'get') {  
                    if (dataType === 'json') {  
                        $.getJSON(url, data, success);  
                    } else {  
                        $.get(url, data, success, dataType);  
                    }  
                } else if (type === 'post') {  
                    $.post(url, data, success, dataType);  
                }*/  
        };  
        document.getElementById("confirm").addEventListener('tap', function() {  
            ajax();  
        });  
    });  
})(mui, document);  

错误提示是
[LOG] : beforeSend:::{"dataType":"json","type":"post","timeout":20000,"url":"https://192.168.100.58:8443/qilianbao/control/testAppAjax","context":null,"accepts":{"script":"text/javascript, application/javascript, application/x-javascript","json":"application/json","xml":"application/xml, text/xml","html":"text/html","text":"text/plain"},"processData":true,"cache":true}
[LOG] : complete:::abort
[LOG] : complete:::[object XMLHttpRequest]

该问题目前已经被锁定, 无法添加新回复