<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ajax参数传递</title>
</head>
<body>
<h1>ajax参数传递</h1>
name:<input type="text" id="name" /><br>
pswd:<input type="password" id="pwd" /><br>
<input type="button" value="获取数据" onclick="submitForm()" />
<script>
function submitForm(){
var name = document.getElementById('name').Value
var pwd = document.getElementById('pwd').Value
url = 'http://httpbin.org/get'
url = url+"?name="+name+"&pwd="+pwd
var xhr = new XMLHttpRequest()
xhr.open('get',url)
xhr.send()
xhr.onload = function(){
console.log(xhr.responseText)
}
}
</script>
</body>
</html>
我的代码是这样的,终端显示
Request URL:
http://httpbin.org/get?name=undefined&pwd=undefined
name:undefined
pwd:undefined