JQuery的Ajax跨域请求的解决方案

来源:互联网 发布:公交线路优化调整方案 编辑:程序博客网 时间:2024/05/22 12:54

js

  var checkUrl = knowledgeUrl+"?merchantSeq="+merchantSeq+"&text=&ditch="+ditch;
        //var checkUrl = "/IM/im/getTextIVR?merchantSeq="+merchantSeq+"&text=&ditch="+ditch;
        $.ajax({
                url: checkUrl,
                dataType: 'jsonp',
                type: 'get',
                jsonp:'callback', //服务端用于接收callback调用的function名的参数
                jsonpCallback:'callback',//callback的function名称

                success: function (data) {
                    var returnCode = data.returnCode;
                    var returnValue = data.returnValue;
                    var merchantNo=data.returnMsg;
              
                    if (returnCode=="0"){
                        $("#startIvr").append(returnValue);
                  
                    }
                }
            });
    }
   



服务端返回数据的示例代码:

    
public void list(HttpContext context) {
    context.Response.ContentType = "text/plain";
    String callbackFunName = context.Request["callback"];
    context.Response.Write(callbackFunName + "([ { id:\"John\"}])");
}

原创粉丝点击