xi_de 2019-02-12 15:27 采纳率: 13%
浏览 747
已结题

MUI.Ajax 调用WebService报错?实在找不到问题。

mui.ajax 调用 WEB Service 报错

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8848' is therefore not allowed access. The response had HTTP status code 500.

图片说明

function getData() {
                var result = "";
                mui.ajax("http://mobile.china-crown.com:8088/Service.asmx/GetCustomerPageList", {
                    data: {
                        "PageIndex": "1",
                        "SiteID": "28822"
                    },
                    dataType: 'json',
                    type: 'get',
                    timeout:10000,//超时时间设置为10秒; 
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    success: function(data) {
                        mui('#Custlist').pullRefresh().endPullupToRefresh(true);
                        //下面这坨都是在拼dom 你可以用jquery 或者是你所熟悉的angular,vue双向绑定
                        var model = JSON.parse(data);
                        $.each(model, function(i, value) {
                            result += '<li class="mui-table-view-cell mui-media">' +
                                '<a href="javascript:;">' +
                                '<div class="mui-media-body">' + value.CustName + '</div>' +
                                '</a>' +
                                '</li>';
                        })
                        var element = document.getElementById("CustomerUlID");
                        element.innerHTML = result;

                    },
                    error: function(xhr, type, errorThrown) {
                        //异常处理;
                        console.log(type);
                    }
                });



            }


[WebMethod]
        //[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void GetCustomerPageList(int PageIndex, int SiteID)
        {
            string JsonStr = "";
            try
            {
                int PageSize = ConfigurationManager.AppSettings["PageSize"].ObjectToInt32();
                //总数量
                int Count = this.GetCustomerListCount(SiteID);

                PageInfo PageResult = new PageInfo(PageIndex, PageSize, Count);


                if (!PageResult.IsBottom)
                {

                    string con = SystemHelper.GetAccountSetConnect();
                    string Sqlcon = ConfigurationManager.ConnectionStrings[con].ConnectionString;

                    SqlParameter[] para = {
                                  new SqlParameter("@SiteID", Convert.ToInt32(SiteID)),
                                   new SqlParameter("@BeginPage", Convert.ToInt32(PageResult.BeginPage)),
                                    new SqlParameter("@EndPage", Convert.ToInt32(PageResult.EndPage))
                                  };

                     DataTable dt = SQLDBHelper.ExecuteQueryDt(Sqlcon, "up_Sel_CustomerList", CommandType.StoredProcedure, 0, para);
                     JsonStr = JsonHelper.DataTableToJson(dt);


                     Context.Response.Charset = "GB2312"; //设置字符集类型  
                     Context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                     Context.Response.Write(JsonStr);
                     Context.Response.End();  


                }
            }
            catch (Exception ex)
            {

            }
            //return JsonStr;
        }
  • 写回答

2条回答 默认 最新

  • o(╯□╰)o ! 2019-02-12 17:05
    关注
    Access-Control-Allow-Origin 跨域了
    用 dataType: 'jsonp' 试试
    
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧