动感超人z字号
动感超人z字号
  • 发布:2015-08-21 17:33
  • 更新:2015-08-21 17:33
  • 阅读:8461

使用ajax能获取数据? 已经测试过mui、jq、js

分类:MUI
mui.init();  
        mui.plusReady(function(){  
        console.log('beginTest');  
        muitest();  
        jqtest();  
        JStest();  
        });  

        function muitest(){  
                console.log('mui test begin');  
            mui.ajax('http://192.168.220.48/api/item',{  
                type:'get',  
                success:function(data){  
                    console.log('mui test success');  
                    console.log(data);  
                },  
                error:function(xhr,typestr,e){  
                    console.log('mui test error');  
                    console.log('mui test error: type='+typestr);  
                }  
            });  
            console.log('mui test end ');  
        }  
        function jqtest(){  
            console.log('jq test begin');  
            $.ajax({  
                url:'http://192.168.220.48/api/item',  
                type:'get',  
                success:function(data){  
                    console.log('jq test success');  
                    console.log(data);  
                },  
                error:function(xhr,state,e){  
                    console.log('jq test error');  
                    console.log('jq test error: state='+state);  
                }  
            });  
            console.log('jq test end ');  
        }  
        function JStest(){  
            console.log('js test begin');  
            var xhr=new XMLHttpRequest();  
            console.log('js test XMLHttpRequest init end');  
            xhr.onreadystatechange=function()  
                {  
                    console.log('js test stateChanged    '+xhr.readyState+'          '+xhr.status);  
                    if (xhr.readyState==4 && xhr.status==200)  
                    {  
                        console.log('success     '+xhr.responseText);  
                    }  
                }  
                console.log('js test set event end');  
                xhr.open('GET','http://192.168.220.48/api/item',true);  
                console.log('js test open end');  
                xhr.send();  
                console.log('js test send end');  
                console.log('js test end ');  
        }

[LOG] : beginTest
[LOG] : mui test begin
[LOG] : mui test end
[LOG] : jq test begin
[LOG] : jq test end
[LOG] : js test begin
[LOG] : js test XMLHttpRequest init end
[LOG] : js test set event end
[LOG] : js test stateChanged 1 0
[LOG] : js test open end
[LOG] : js test send end
[LOG] : js test end
--------等待超时后
[LOG] : mui test error
[LOG] : mui test error: type=abort
[LOG] : js test stateChanged 4 0

疑惑点
1/为什么onreadystatechange 事件只触发了两次
2/为什么第二次触发时 readyState=4 而status却是0

0 关注 分享

要回复文章请先登录注册

zhaoyari

zhaoyari

没看出来,请明示
2015-08-23 21:11
动感超人z字号

动感超人z字号 (作者)

是我二逼,犯了个低级错误
2015-08-21 17:50