加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

nodejs jsonp跨域使用 服务器端

发布时间:2020-12-16 19:17:57 所属栏目:百科 来源:网络整理
导读:var yourCallbackName = function(rs){ console.dir(rs); //此处填写success后的处理程序。 } $.ajax({ async:false, type: "get", url: "http://localhost:8060/common/imagecrop?callback=yourCallbackName", data: "type="+options.imageType+"_id="+opti

var yourCallbackName = function(rs){

console.dir(rs);

//此处填写success后的处理程序。

}


$.ajax({

async:false,
type: "get",
url: "http://localhost:8060/common/imagecrop?callback=yourCallbackName",
data: "type="+options.imageType+"&_id="+options.targetId,
dataType: "jsonp"

});


其中yourCallbackName为 毁掉函数名称,但是必须写在js全局范围内,因为jsonp回调用它的时候,是放在单独的<script>里面。


服务器端是这样:res.end("yourCallbackName("+JSON.stringify({code : 1,message : '我了个去啊'})+");");

服务器端的写法,这种格式是对的,其它的格式,有没有就不知道了,试了好多都不行。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读