Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parse POST results token

    I'm making a javascript POST that returns some information in this format. It's copied from the web API website I'm developing from.

    Returns a token on success.

    Code:
    {
    	"errors": [
    	], 
    	"warnings": [
    	], 
    	"data": {
    		"token": "ta98585435afabcf26319e2038a09f40"
    	}, 
    	"page": {
    		"current": 1, 
    		"total": 1
    	}
    }
    How can I get the data.token bit out specifically?

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    er, data.token?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The result comes back as an array of information. There is an element called data.token.

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    When you make your call to the server to get the JavaScript, it comes back as a string and requires converting to JavaScript code using eval()

    It's a good idea to error handle it:
    Code:
    try {
    var json = eval(YourServerResponseJavaScript);
    } catch(e) {
    alert('Invalid JS from server');
    return;
    }
    
    
    var theToken = json.data.token;
    Hope this helps

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

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