<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax解决跨域问题</title>
<script src="jquery-3.0.0.min.js" type="text/javascript"></script>
</head>
<body>
<script>
$.ajax({
type:"POST",
url:"postDemo.php",
data:{
"url":"http://192.168.4.101:90/PHPStudy4/server.php",
"username":"admin",
"password":"admin",
},success:function(data){
var result=eval("("+data+")");
console.log(result);
}
})
</script>
</body>
</html>
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016-7-21
* Time: 10:12
*/
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// echo json_encode(array("111"=>"112"));
if (isset($_POST["url"]) && isset($_POST["username"]) && isset($_POST["password"])) {
$result = postDemo($_POST["url"], array("username" => $_POST["username"], "password" => $_POST["password"]));
echo $result;
} else {
echo json_encode(array("msg2" => "!!!!!!!!!!!!!!!!!!!!!error!!!!!2"));
}
} else {
echo json_encode(array("msg" => "error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"));
}
function postDemo($url, $data)
{
$query = http_build_query($data);
$options = array(
"http" => array(
"header" => "Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length:" . strlen($query) . "\r\n" .
"User-Agent:MyAgent/1.0/r/n",
"method" => "POST",
"content" => $query
)
);
$content = stream_context_create($options);
$result = file_get_contents($url, false, $content);
return $result;
}
//echo postDemo("http://192.168.4.101:90/PHPStudy4/server.php",array("username"=>"admin","password"=>"admin"));
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有