zl程序教程

您现在的位置是:首页 >  Javascript

当前栏目

html请求跨域和referer

2023-04-18 12:43:49 时间

后端请求

  • 后端redirect重定向页面

使用form请求,ajax请求要单独设置跳转(ajax是页面局部刷新)

  • 修改请求头部

w.Header().Set(“Access-Control-Allow-Origin”, “*”) w.Header().Set(“Access-Control-Allow-Headers”: “X-Requested-With,X_Requested_With,X-PINGOTHER,Content-Type”); w.Header().Set(“Access-Control-Allow-Headers”,“Content-Type” )

html

  • 前端重定向,window.kk 或者replace
  • script标签回调
 function showData (result) {}
$("head").append("<script src='http://localhost:9090/student?callback=showData'></script>");

jquery封装了以上操作jsonp

 function showData (result) {}
$.ajax({
	url: "http://localhost:9090/student",
	type: "GET",
	dataType: "jsonp",  //指定服务器返回的数据类型
	jsonpCallback: "showData",
	})

重定向检查referer

html添加meta标签,请求不带referer

<meta name="referrer" content="never">