码迷,mamicode.com
首页 > Web开发 > 详细

温故而知新 监听 XMLHttpRequest 发起请求

时间:2018-11-18 11:32:13      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:view   lib   color   body   work   ima   github   oca   script   

window.XMLHttpRequest.prototype.open 可以监听 XMLHttpRequest 。但不能监听fetch请求。

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- jquery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>
</body>
<script>
var _open = window.XMLHttpRequest.prototype.open
var _send = window.XMLHttpRequest.prototype.send

// https://github.com/Tencent/vConsole/blob/dev/src/network/network.js#L271
window.XMLHttpRequest.prototype.open = function() {
    console.log(20181117200649, arguments)
    return _open.apply(this, arguments)
}

// fetch("http://localhost/fuck.php").then(response => {
//     // console.log(20181117201438, response.json())
//     return response.json()
// }).then(data=>{
//     console.log(20181117201450, data)
// })

$.ajax({
    url: "http://localhost/fuck.php",
    success: function (data) {
        console.log(20181117133228, data);
    }
})
</script>
</html>

 

技术分享图片

 

温故而知新 监听 XMLHttpRequest 发起请求

标签:view   lib   color   body   work   ima   github   oca   script   

原文地址:https://www.cnblogs.com/CyLee/p/9977143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!