问题
I am trying to use jquery-mockjax library to mock ajax, but I cannot see any response. My code is as follow :
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="components/jquery/jquery.js"></script>
<script src="components/jquery-mockjax/jquery.mockjax.js"></script>
<script>
$(function(){
$.mockjax({
url: '/test/inline',
contentType: "text/json",
responseTime: 0,
responseText: {
say: 'Hello world!'
}
});
$('#btn').click(function(){
$.ajax({
url: '/test/inline',
type: "GET",
dataType: 'json',
success: function(json) {
alert('You said: ' + json.say);
},
complete: function() {
$.mockjaxClear();
alert('completed');
}
});
}
);
});
</script>
</head>
<body>
<button id="btn">Get</button>
</body>
</html>
Is there anything I am missing?
回答1:
I had this same problem and was banging my head for half an hour, and shouting "why?"
Try downgrading jQuery to 1.*
回答2:
ResponseTime increase.
responseTime: 10,
来源:https://stackoverflow.com/questions/16411978/no-response-with-jquery-mockjax