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' 试试
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?