原生的ajax请求方法:
$("#send").click(function(){
var data = {
name:"zhangsan",
age:18,
sex:"male"
}
var xhr = new XMLHttpRequest(); //创建一个ajax对象
xhr.onreadystatechange = function(){ // 监听ajax
if(xhr.readystate == 4){
if(xhr.status == 200){ // 请求发送成功
console.log(xhr)
}
}
};
xhr.open("open","url",true);
xhr.send(data);
})
jquery中的ajax:
window.onload = function(){
var btn = document.querySelector("#btn");
btn.onclick = function(){
var keywordValue = document.querySelector("#keyword").value;
$.ajax({
url:"https://suggest.taobao.com",
data:{quest: keywordValue},
dataType:"jsonp",
success:function(data){
console.log(data)
}
})
}
}