Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4333798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:26:31+00:00 2026-05-21T10:26:31+00:00

I have defined an ajax dataFilter for my jQuery calls that return JSON data

  • 0

I have defined an ajax dataFilter for my jQuery calls that return JSON data to ensure that .Net-encoded dates are automatically converted to JavaScript dates on return:

$.ajaxSetup({
    dataFilter: function(data, type) {
        var rx = /"\\\/Date\(([0-9]+)\)\\\/"/g;
        if(type == 'json' && typeof(data) == 'string' && rx.test(data)) {
            var obj = JSON && JSON.parse ? JSON.parse(data) : eval(data);
            replaceMicrosoftJSONDates(obj);
            return obj;
        }
        return data;
    }
});

The replaceMicrosoftJSONDates function works fine; it recursively iterates through the object and replaces strings matching the appropriate date format string with actual JavaScript dates, but here it is for testing purposes:

function replaceMicrosoftJSONDates(obj) {
    for(var p in obj)
        switch(typeof(obj[p])) {
            case 'string':
                var match = /^\/Date\(([0-9]+)\)\/$/.exec(obj[p]);
                if(match) obj[p] = new Date(parseInt(match[1]));
                break;
            case 'object':
                replaceMicrosoftJSONDates(obj[p]);
                break;
        }
}

The problem is with the dataFilter function. If I return the modified JSON object, null is sent as the data parameter to the ajax success callback:

$.ajax({
    type: 'GET',
    cache: false,
    url: __appPath + 'path/to/my/page',
    success: function(data) {
        console.log(data); // displays null
    }
});

As far as I can tell, the jQuery private function involved in this process is ajaxConvert, which you can see at https://github.com/jquery/jquery/blob/master/src/ajax.js#L897-979

Keep in mind the following:

  • This is not a cross-domain scripting call
  • The server is return an HTTP200 (OK) response and the responseText has the full data
  • The data is being sent correctly to the dataFilter function
  • The dataFilter function appears to correctly parsing and modifying the response and returning a valid JavaScript object, already parsed and ready to consume

If I return a string from the dataFilter function, jQuery does its job correctly and sends me a parsed JSON object. If I return a pre-parsed JavaScript object, jQuery sends null to my success callback. I am using jQuery 1.5.2 in this case and this filter used to work in other applications and older versions of jQuery. Now all of a sudden it doesn’t seem to work anymore.

SOLUTION

Here: http://forum.jquery.com/topic/datafilter-function-and-json-string-result-problems

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:26:32+00:00Added an answer on May 21, 2026 at 10:26 am

    Rick Strahl had problem similiar to this recently (this seems to be specific for jQuery 1.5.2). As I don’t wan’t to copy his work, here is his solution which should easly guide you to solve your problem: http://codepaste.net/i89xhc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.