解决访问后台服务出现跨域问题,设置jsonp格式

来源:互联网 发布:手机淘宝咸鱼二手网 编辑:程序博客网 时间:2024/06/05 15:37

1.后台代码

String dataCallback=request.getParameter("dataCallback");
if(dataCallback!=null){jsonStr1=(dataCallback+"("+jsonStr1+")");}out.write(jsonStr1);out.close();

前端发送请求调用:

  var param = {};            param.thematicType = this._mThematicType;            param.systemType = this._mSystemType;            param.layerName = this.getLayerENName();            param.appendMode = appModel;            param.json = encodeURIComponent(encodeURIComponent(JSON.stringify(this._mData)));            param.serviceMethod = "updateData";            DPS.$.ajax({                type: "post",                url: thematicMap.getUrl() + "/ClusterService",                dataType : "jsonp",                data: param,                jsonp: "dataCallback",                 // 异步请求                async: true,                cache: false,                success: function (data) {                                },                error: function (res) {                console.log(res)                                   }            });


原创粉丝点击