This question is locked. New answers and comments are not allowed.
Hi,
The current version of the grid has problems with Dates in AJAX requests when using jQuery 1.4. This is because jQuery 1.4 does strict JSON parsing so will throw a parsing error when it encounters "new Date" in the JSON.
To fix things, change your telerik.grid.js as follows:
1. Add the following after the line starting var dateRegExp at the top of the file:
2. Change the options in ajaxRequest to the following:
Sadly jQuery 1.4 doesn't allow you to specify a reviver function to parse to the JSON.parse call (I've asked for that to be added to jQuery) which would make the patch simpler; this is why I'm specifying a type of text and parsing manually in the code above. Note that I'm not doing any regular expression checks to make sure this is valid JSON; you might want to add that in if you can't trust the JSON. (Have a look at the httpData method in jQuery for how to do this)
The current version of the grid has problems with Dates in AJAX requests when using jQuery 1.4. This is because jQuery 1.4 does strict JSON parsing so will throw a parsing error when it encounters "new Date" in the JSON.
To fix things, change your telerik.grid.js as follows:
1. Add the following after the line starting var dateRegExp at the top of the file:
| var dateReviverRegExp = /\/Date\((.*?)\)\//g; |
| var dateReviver = function(key, value) |
| { |
| if (typeof (value) === "string") |
| { |
| var match = dateReviverRegExp.exec(value); |
| if (match) |
| { |
| return new Date(parseInt(match[1])); |
| } |
| } |
| return value; |
| } |
2. Change the options in ajaxRequest to the following:
| var options = { |
| type: 'POST', |
| url: this.ajaxUrl, |
| dataType: 'text', |
| error: $t.bind(this, function(xhr, status) |
| { |
| if ($t.ajaxError(this.element, 'error.Grid', xhr, status)) |
| return; |
| if (status == 'parsererror') |
| alert('Error! The requested URL did not return JSON.'); |
| }), |
| complete: function() |
| { |
| clearTimeout(loadingIconTimeout); |
| statusIcon.removeClass('t-loading'); |
| }, |
| success: $t.bind(this, function(data) |
| { |
| // Parse the JSON manually so we can convert the dates to true Date objects. |
| if (window.JSON && window.JSON.parse) |
| { |
| data = window.JSON.parse(data, dateReviver); |
| } |
| else |
| { |
| data = (new Function("return " + data.replace(dateRegExp, 'new Date($1)')))(); |
| } |
| data = data.d || data; //Support the `d` returned by MS Web Services |
| this.total = data.total || data.Total || 0; |
| this.dataBind(data.data || data.Data); |
| }) |
| }; |
Sadly jQuery 1.4 doesn't allow you to specify a reviver function to parse to the JSON.parse call (I've asked for that to be added to jQuery) which would make the patch simpler; this is why I'm specifying a type of text and parsing manually in the code above. Note that I'm not doing any regular expression checks to make sure this is valid JSON; you might want to add that in if you can't trust the JSON. (Have a look at the httpData method in jQuery for how to do this)