接口中可以查到数据,为什么却获取不到呢?

baiyygynui888
  • 855

问了好多人,都说取不到数据是因为跨域了,为什么会跨域呢?

         (function($) {
                //阻尼系数
                var deceleration = mui.os.ios?0.003:0.0009;
                $('.mui-scroll-wrapper').scroll({
                    bounce: false,
                    indicators: true, //是否显示滚动条
                    deceleration:deceleration
                });
                $.ready(function() {
                    //循环初始化所有下拉刷新,上拉加载。
                    $.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
                        $(pullRefreshEl).pullToRefresh({
                            down: {
                                callback: function() {
                                    var self = this;
                                    setTimeout(function() {
                                        var ul = self.element.querySelector('.mui-table-view');
                                        ul.insertBefore(createFragment(ul, index, 10, true), ul.firstChild);
                                        self.endPullDownToRefresh();
                                    }, 1000);
                                }
                            },
                            up: {
                                callback: function() {
                                    var self = this;
                                    var arr = {
                                        callback: getAjaxData
                                    };
                                    setTimeout(function() {
                                        var ul = self.element.querySelector('.mui-table-view');
                                        ul.appendChild(createFragment(ul, index, 5, arr));
                                        self.endPullUpToRefresh();
                                    }, 1000);
                                }
                            }
                        });
                    });
                    
                    var dataArr = [];
                    var getAjaxData = function(){
                        var url = 'http://www.beta.anviz.com/myanviz/faq/ajax.html?category_id=0';
                        mui.ajax({
                            type: 'GET',
                            url: url,
                            dataType: 'json',
                            success: function(data) {
                                console.log(data);
                                var list = data.data;
                                for(var i = 0; i < list.length; i++) {
                                    console.log('list' + list);
                                    var item = list[i];
                                    var faqName = item.faqName;
                                    var faqId = item.faqId;
                                    
                                    var dataEntity = {};
                                    dataEntity.faqName = faqName;
                                    dataEntity.faqId = faqId;
                                    
                                    dataArr.push(dataEntity);
                                }
                                return dataArr;
                            }
                        });
                    }
                    
                    var createFragment = function(ul, index, count, reverse) {
                        var fragment = document.createDocumentFragment();
                        var li;
                        var arr = reverse;
                        for (var a = 0; a < count; a++) {
                            li = document.createElement('li');
                            li.className = 'mui-table-view-cell';
                            
                            li.innerHTML = '<li class="mui-table-view-cell" data-id=' + faqId + '><a class="mui-navigate-right"><p class="anviz-ellipsis js-ellipsis">' + faqName + '</p></a></li>'
                            fragment.appendChild(li);
                        }
                        return fragment;
                    };
                });
            })(mui);
回复
阅读 2.1k
3 个回答

是不是ajax请求的路径的问题,为什么要写全路径呢

先检查返回的是字符串还是json,字符串需要JSON.parse

console.log出来的data是什么,因为你的Hander的返回格式不是json。你把你的handler的返回格式,设置成json即可。

你知道吗?

宣传栏