Thread: JSON Headache
View Single Post

  #2 (permalink)  
Old 17-07-2008, 05:09 PM
davkell davkell is offline
Coder
Recent Blog: Give a Gift & BTKids
 
Join Date: Jul 2007
Location: Galway
Posts: 68
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
davkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud ofdavkell has much to be proud of
Default Sorted :)

Have to love that - I've been staring at it for ages, and one minute after I posted above, I tripped over the solution.

The problem was (just in case anyoune suffers the same) - I was passing the JSON response from one function to another. To do this I should have parsed it both before and after sending.

Code:
function getAll(){
    var request = google.gears.factory.create('beta.httprequest');
    request.open('GET', '/find/gearssetup/');
    
    request.onreadystatechange = function() {
    
      if (request.readyState == 4) {
    try{
            var response = request.responseText;
            var r = {};
            r = eval("(" + response + ")");    // ** Needed to Parse here too
            processAll(r);            
        }// try
        catch(ex){
            log("Error: " + ex.message);
        } // catch
      }    // readystate
    };    // onstatechange
    
    request.send();
} // getAll()

function processAll( response ){

     var jsResp = eval("(" + response + ")");    
....
....
}
Dave.
__________________
Website Design Galway | Blog
Reply With Quote