I have AJAX responses where all key,value pairs are quoted. I want to remove the quotes from any values that are numbers. I need to do this globally, for all AJAX requests, with minimal effort.
I am using jQuery.getJSON for the majority of the requests, and I want a solution that doesn't require tweaking each of the current AJAX requests individually. (I don't want to add a JSON.parse(text,myreviver) call in every one of the existing $.getJSON calls.)
For example:
Received: {"age":"31", "money": "-1.329"}
Want: {"age": 31, "money": -1.329}
How can I do this, for all AJAX requests?
My current end-goal is to use JSON.parse(text, reviver) to process the data (thanks to this question). I don't know how to hook this into jQuery.ajax, though.
I have tried using ajaxSuccess(), but it doesn't appear to chain-process any data. For example:
$(document.ajaxSuccess) ( function(j) {
JSON.parse(j, myReviver);
}
.getJSON(url, data, function(j) {
// The data in this success function has not been through myReviver.
}
How can I:
- use a reviver function in
jQuery.getJSON, or - process the AJAX response in a global
successfunction before it reaches other success functions?