GetJSON: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
getJSONP(''url'',''data'',''callback'')
GetJSON(''url'',''data'',''callback'')


== Description ==
== Description ==


getJSONP loads JSON-encoded data from the server using a GET HTTP request.  
GetJSON loads JSON-encoded data from the server using a GET HTTP request.  


''url'' is the location that data is being requested from.
''url'' is the location that data is being requested from.
Line 9: Line 9:
''data'' is the information about the request. If multiple fields are being passed, include them in a single string, separated by ampersand (&) characters. It's best to do an [[EncodeURIComponent/decodeURIComponent|encodeURIComponent]]() to the data to make sure that spaces and other special characters are properly formatted.
''data'' is the information about the request. If multiple fields are being passed, include them in a single string, separated by ampersand (&) characters. It's best to do an [[EncodeURIComponent/decodeURIComponent|encodeURIComponent]]() to the data to make sure that spaces and other special characters are properly formatted.


''callback'' is the name of the function in your program to be called when the request is complete. Since the request may take a little while to complete, your app will continue execution immediately after the getJSONP() function is called. The results will not be available until the ''callback'' function is called. The returned data is passed to the ''callback'' function.
''callback'' is the name of the function in your program to be called when the request is complete. Since the request may take a little while to complete, your app will continue execution immediately after the GetJSON() function is called. The results will not be available until the ''callback'' function is called. The returned data is passed to the ''callback'' function.
 
This function is a wrapper for the jQuery $.getJSON() function. It works identically.


== Example ==
== Example ==
Line 16: Line 18:
Function btnLoad_onclick()
Function btnLoad_onclick()
   Dim city = encodeURIComponent(txtCity.value)
   Dim city = encodeURIComponent(txtCity.value)
   GetJSONP("http://api.openweathermap.org/data/2.5/weather","q=" & city, weatherData)
   GetJSON("http://api.openweathermap.org/data/2.5/weather","q=" & city, weatherData)
End Function
End Function



Revision as of 21:48, 28 January 2014

GetJSON(url,data,callback)

Description

GetJSON loads JSON-encoded data from the server using a GET HTTP request.

url is the location that data is being requested from.

data is the information about the request. If multiple fields are being passed, include them in a single string, separated by ampersand (&) characters. It's best to do an encodeURIComponent() to the data to make sure that spaces and other special characters are properly formatted.

callback is the name of the function in your program to be called when the request is complete. Since the request may take a little while to complete, your app will continue execution immediately after the GetJSON() function is called. The results will not be available until the callback function is called. The returned data is passed to the callback function.

This function is a wrapper for the jQuery $.getJSON() function. It works identically.

Example

Function btnLoad_onclick()
  Dim city = encodeURIComponent(txtCity.value)
  GetJSON("http://api.openweathermap.org/data/2.5/weather","q=" & city, weatherData)
End Function

Sub weatherData(data)
  MsgBox "Temperature is " & data.main.temp - 273.15
End Sub

Related Items

Ajax