Rumah > Soal Jawab > teks badan
<form id="loginForm" method="post" onsubmit="return false;"> <div> <input type="text" name="userid" id="userid" class="userid" placeholder="id" autocomplete="off" onfocus="" onblur="" /><!-- autocomplete="off" 关闭自动补全 --> </div> <div> <input type="text" name="username" id="username" class="username" placeholder="用户名" autocomplete="off" onfocus="" onblur="" /> </div> <div> <input type="password" name="password" id="password" class="password" placeholder="密码" oncontextmenu="return false" onpaste="return false" /> <!-- oncontextmenu="return false"关闭右键打开菜单功能 onpaste="return false"关闭粘贴功能 --> </div> <button id="submit" type="submit" onclick="mysubmit();">登 录</button> </form>
表单结构
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 Gagal memuatkan http://localhost/phpuationProject/graduationProject/login/graduation /server/login.php' kepada 'http://localhost/graduationProject/browser/flappybirds/index.html' telah disekat oleh dasar CORS: Tiada pengepala 'Access-Control-Allow-Origin' hadir pada sumber yang diminta. Oleh itu, 'null' asal tidak dibenarkan akses.
Alone882019-04-19 09:04:02
Isu merentas domain, php ditambah pengepala('Access-Control-Allow-Origin:*');