Benny's Blog
Navigation: Home » Archives for Dezember 2011
27. Dezember 2011

With jQuery you could easily parse a JSON (which is an object in JavaScript Object Notation). The method parseJSON of jQuery translates the JSON even into the corresponding JavaScript data types. As an example I have chosen the following JSON:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
        "firstName": "Joe",
        "lastName" : "Black",
        "age"      : 28,
        "address"  :
        {
          "streetAddress": "1st Street",
          "city"         : "New York",
          "state"        : "NY",
          "postalCode"   : "10021"
        },
        "phoneNumber":
        [
          {
            "type"  : "home",
            "number": "212555-1234"
          },
          {
            "type"  : "fax",
            "number": "646555-4567"
          }
        ],
        "married" : true,
        "developer" : true	
}

This JSON contains nested objects like address, an array like phoneNumber and key-value pairs of different types like firstName (string), age (number) and married (boolean).

Here it is shown how it is parsed:

…weiterlesen

23. Dezember 2011

Over the years many ways have been created in order to authenticate through Facebook. One of the easiest ways is to use the Facebook Markup Language (FBML). However, from January 2012 is FBML is no longer supported. Who wants to use Facebook Connect to login and logout then, should use the JavaScript SDK provided by Facebook. This supports authentication via OAuth 2.0, which is the recommended way to handle authentication. I programmed an example, that shows how to login and logout with the JavaScript SDK. This example is based on the current JavaScript SDK methods and does not use deprecated methods (because in July 2011 there were some changes).

…weiterlesen

23. Dezember 2011

If you have any problems with the Facebook game Tetris Battle, then you should see if third-party cookies are enabled in your browser. Often they are not. Therefore, the error message “We are having difficulties logging into Facebook. Please try again later.” appears in many browsers.

To fix this problem, you can do the following:

Thanks to the Tetris Battle Online Customer Support for this information!

15. Dezember 2011

If you explicitly convert a JavaScript variable to a number (e.g. by using the parseInt function), then you have to check if the value of the converted number is really a number. In case that it is not, it will present you NaN (Not a Number). You can check for NaN with the isFinite function.

Example:

1
2
3
4
5
6
// Check for hexadecimal value
var convertedNumber = parseInt('G', 16);
if(isFinite(convertedNumber) == false)
  alert('The value of the converted number is NaN!');
else
  alert('The number is: '+convertedNumber);