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=11111",
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=111111;
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 获得票据,成功登录