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

jsonp 使用记录(二)跨域设置cookie

发布时间:2020-12-16 19:00:43 所属栏目:百科 来源:网络整理
导读:html:!DOCTYPE htmlhtmlheadmeta charset="UTF-8"titleInsert title here1/titlescript type="text/javascript" src="jq.js"/script/headbody?php echo "s";?script type="text/javascript"jQuery(document).ready(function(){ $.ajax({ type: "get",async:
html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here1</title>
<script type="text/javascript" src="jq.js"></script>
</head>
<body>
<?php echo "s";?>
<script type="text/javascript">
	jQuery(document).ready(function(){
	   $.ajax({
	        type: "get",async: false,url: "http://www.services.com/dadianlogin/login?username=1111&password=22222",dataType: "jsonp",jsonp: "callback",//传递给请求处理程序或页面的,用以获得jsonp回调函数名的参数名(一般默认为:callback)
	        jsonpCallback:"returnjs",//自定义的jsonp回调函数名称,默认为jQuery自动生成的随机函数名,也可以写"?",jQuery会自动为你处理数据
	        crossDomain:true,success: function(json){
	            alert(json.code);
	        },error: function(){
	            alert('fail');
	        }
	    });
	});
</script>
</body>
</html>

接收后台:
<?php
class dadianlogin{
	public function login(){
		$username=$_GET['username'];
		$password=$_GET['password'];

		$ticke=222221;
		header("Location:http://www.return.com/dandian/setcookie?ticke=$ticke");
	}
}

跨域后台:
<?php
class dandian{
//return 域下会设置一个cookie
	public function setcookie(){
		$ticke=$_GET['ticke'];
		setcookie("ticke",$ticke);
		$code='yes';
		echo 'returnjs({"code":"'.$code.'"})';
		die;
	}
}


应用场景:send传输数据进行登录 services负责验证用户正确与否并生成安全票据 return 获得票据,成功登录

(编辑:李大同)

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

    推荐文章
      热点阅读