0

reading a tutorial of Ajax, I found a jQuery line like this:

$.get("www.nameurl.com/...", function(resp) {
    alert("The reply is " + resp);
})

I'm not going to ask you explanations about Ajax and the particular meaning of this lines.

What I don't understand is that jQuery input "$.get()".

I usually read or use $(document), $(window), $(".classname") etc, but I never used a kind of formulation like $.get().

Can you provide me some explanations?

marco
  • 1,152
  • 1
  • 9
  • 20

2 Answers2

7

The $.[functionName] construct is used for jQuery utility functions and other jQuery functions that do not perform operations on a set of selected elements. You will find others such as $.map(), $.each(), etc.

To see other functions using this syntax checkout the documentation

Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • 2
    Perhaps "...is used for jQuery functions that aren't tied to a jQuery set." I didn't think "utility function" was incorrect in any significant way, but... – T.J. Crowder Oct 03 '13 at 10:05
0

This method fetches data using HTTP GET Method, It accepts few parameters for executing this method .

 jQuery.get( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

your $get.() load data from the server using a HTTP GET request. Here

url

Type: String A string containing the URL to which the request is sent.

data

A plain object or string that is sent to the server with the request.

success(data, textStatus, jqXHR)

A callback function that is executed if the request succeeds.

dataType

The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).

Its actually a shorthand for Ajax function which is equivalent to -Here .

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

.get()

Retrieve the DOM elements matched by the jQuery object

Without a parameter, .get() returns an array of all of the elements: Here

Suraj Singh
  • 4,041
  • 1
  • 21
  • 36