I'm using mockjax to simulate an Ajax call, but I'm experiencing that the data received by my Ajax callback is different from what I pass to mockjax (via the 'responseText' parameter). In this example, I've chosen the response to be '14.0', but the callback receives '14' instead:
$.mockjax({
url: "/test",
contentType: "text/json",
responseText: "14.0"
});
$.ajax({
url: "/test",
datatype: "json"
}).done(function(data) {
alert(data);
});
Why is it that the received data is different from what I specify to responseText
? See this fiddle for a working example; a popup dialog will show the string received by the callback, should be '14'.
EDIT:
This is the popup I get when running the fiddle, demonstrating the altered response from mockjax.
Also fixed the fiddle.
If you change two small things the above snippet will work as you expect.
In the above code snippet the contentType mentioned in $.mockjax is "text/json". In that case the responseText needs to be an
object
that represents the JSON. https://github.com/appendto/jquery-mockjaxAlso, in the $.ajax call the
datatype
key should bedataType
http://api.jquery.com/jquery.ajax/I've made the changes in the following jsFiddle http://jsfiddle.net/elijahmanor/BtuW8/
I hope that helps you past the issue.