表单结构
function mysubmit(){
var xhr ;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xhr=new XMLHttpRequest();
}
else
{
// IE6, IE5 浏览器执行代码
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("POST","http://localhost/graduationProject/server/login.php",true);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xhr.send("userid=1111&username=1111&password=1111");
// body...
}ajax请求
浏览器报错:index.html:1 Failed to load http://localhost/graduationProject/server/login.php: Redirect from 'http://localhost/graduationProject/server/login.php' to 'http://localhost/graduationProject/browser/flappybirds/index.html' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
跨域问题, php加入 header('Access-Control-Allow-Origin:*');