www.webdeveloper.com
Results 1 to 4 of 4

Thread: json deserialized object has ISError Property by default?

  1. #1
    Join Date
    Jul 2006
    Posts
    146

    json deserialized object has ISError Property by default?

    In the code below, using prototype library, the Ajax.request returns a set of data which i can see is populated in the var response object.

    There is alot of data in the var response object, but the IsError and AppItems object are undefined.

    Is there supposed to be an ISError property by default, or would this have to be defined in the AJAX data which is returned?

    Code:
    new Ajax.Request(url, {
                method: 'get',
                onSuccess: function(transport) {
                    // Parse out serialized response
                    var response = transport.responseText.evalJSON();  // this has many properties but, not IsError 
                    if (response.IsError) {
                        setResultMessage(response.Message, response.IsError);
                        return;
                    }
                    else
                    {
                        // Always start at first page
                        currentPage = 1;
                        
                        // Fill the search results
                        fillSearchResults(resultsTable, response.AppItems);  //this response.AppItems is never defined either
                        return;
                    }
                }
            }
        );
    Thank you for input.

  2. #2
    Join Date
    May 2009
    Posts
    6

  3. #3
    Join Date
    Jul 2006
    Posts
    146

    That wasn't a helpful link

    The link you sent speaks about how to send a request to AJAX, my troubles have to do with the transport.responseText.evalJSON() method, and the object that is created.

    I want to know if there is a default IsError property for the object which is returned from that transport.responseText.evalJSON() method, and some possibly some other specifics surrounding that object.

  4. #4
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    The evalJSON method appears to be added to the String class by Prototype. I believe those properties are there so you can turn any string into a JSON object, and if there was a syntax error in the string, the IsError property would be true:
    Code:
    var foo = "my string";
    var bar = "{age:13}";
    
    var fooObj = foo.evalJSON();
    var barObj = bar.evalJSON();
    
    if (fooObj.IsError) {
      alert("foo isn't valid JSON");
    }
    
    if (barObj.IsError) {
      alert("bar isn't valid JSON");
    }
    I think that's how it's supposed to be used.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles