Closed blocknotes closed 7 years ago
Did you load and register FakeRest before jQuery is loaded?
How could I do it?
I tried also to inject jQuery later on (for testing):
<script>
setTimeout( function() {
(function() {
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
})();
}, 1000 );
</script>
Insert all the script tags mentioned in the Readme Usage section before loading jQuery.
That's what I tried.
Here are my script tags:
<script src="FakeRest/dist/FakeRest.min.js"></script>
<script src="sinon/sinon-1.17.3.js"></script>
<script src="jquery/jquery-1.12.4.min.js"></script>
I tried in head or in the end of the body, same result.
If I inspect the ajax requests they are the same (headers are equals)
I put my code on plnkr if you want to take a look: https://plnkr.co/edit/unEDpD8mMMhUUqwhfAQQ?p=preview
@fzaninotto @blocknotes problem is demonstrated here: http://codepen.io/airtonix/pen/BQKMjp
@fzaninotto @blocknotes Ok so it looks like when you set async: false
on the jQuery.ajax
call, it succeeds and fakerest
can intercept.
But change it back to the default of async: true
, then fakerest
can't intercept.
I think the problem lies in sinon fake server
@airtonix using async: false
works for me too, probably it is caused by Sinon as pointed by @fzaninotto
Here is how I init (data is a simple hash):
Using pure JS works as expected:
If I try with jQuery the request seems to be caught but I get no response:
No console output.
The same with angularJS:
Any idea?