溫故而知新 監聽 XMLHttpRequest 發起請求


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>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM