// 监听键盘空格事件,把空格事件禁止,因为页面上按空格键会滚动页面
$(window).keydown(function(event) {
event = event || window.event;
if (event.keyCode === 32) {
return false;
}
})
$(window).keyup(function(event) {
event = event || window.event;
if (event.keyCode === 32) {
playControl();
return false;
}
else if (event.keyCode === 27) {
$('.fullScreen').removeClass('cancleScreen');
$('#willesPlay .playControll').css({}).removeClass('fullControll');
} else if (event.keyCode === 39) {
createPlay()
_hmt.push(['_trackEvent', 'video', 'play', 'pv'])
} else if (event.keyCode === 37){
playPrev()
_hmt.push(['_trackEvent', 'video', 'play', 'pv'])
}
event.preventDefault();
});
$.ajax({
url: '/api/user/collected-author/',
type: 'post',
contentType: 'application/json',
data: JSON.stringify({'author_id': author_id, 'source': t}),
success:function(resp){
if(resp.code === 200){
$('#follow-user').hide()
$('.message').text('关注成功!')
$('.message').show(300).delay(1000).hide(300);
}else if (resp.code === 202){
$('.message').text('您已关注此作者')
$('.message').show(300).delay(1000).hide(300);
} else if (resp.code === 403) {
$('.message').text('请先登录')
$('.message').show(300).delay(1000).hide(300);
}
}
})
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?67cfc45e6393b98852546ccd940217ac";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
XMLHttpRequest
使用GET方法的具体代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<script>
var httpxml ;
if(window.XMLHttpRequest){
//大多数浏览器
httpxml = new XMLHttpRequest();
}else{
//古董级浏览器
httpxml = new ActiveXObject("Microsoft.XMLHTTP");
}
httpxml.onreadystatechange =function () {
if(httpxml.readyState==4 && httpxml.status==200){
console.log(httpxml)
}else{
console.log("发生了错误");
}
}
httpxml.open("get","http://localhost:8080/ServletDemo",true);
httpxml.send();
</script>
使用POST的方法具代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<script>
var httpxml ;
if(window.XMLHttpRequest){
//大多数浏览器
httpxml = new XMLHttpRequest();
}else{
//古董级浏览器
httpxml = new ActiveXObject("Microsoft.XMLHTTP");
}
httpxml.onreadystatechange =function () {
if(httpxml.readyState==4 && httpxml.status==200){
console.log(httpxml)
}else{
console.log("发生了错误");
}
}
httpxml.open("post","http://localhost:8080/ServletDemo",true);<br> xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpxml.send("name='参数1'&name1='参数2'");
</script>