Skip to content

Instantly share code, notes, and snippets.

@ijt
Created March 16, 2020 19:02
Show Gist options
  • Save ijt/761c82d9ab47d76d7d28142caf5371e6 to your computer and use it in GitHub Desktop.
Save ijt/761c82d9ab47d76d7d28142caf5371e6 to your computer and use it in GitHub Desktop.
Intercept Ajax calls and make them do something else
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div id="d">nothing here yet</div>
<script>
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(body) {
Object.defineProperty(this, 'responseText', { writable: true });
this.responseText = '' + Date();
this.onload();
};
$('#d').load('http://example.com/this/wont/really/be/loaded');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment