jQuery Flashcards

0
Q

CDN

A
  • Content Delivery Network
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

jQuery

A
  • a popular JavaScript library that simplifies making AJAX requests
  • selects page elements, updates the Document Object Model (DOM), and creates animations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

$(‘#ajax’).load(‘sidebar.html’);

A
  • it loads the contents of the sidebar.html file into an HTML element with the ID of “ajax.”
  • this method must be chained onto a jQuery selection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
var url = 'http://website.com/posts';
var data = {object}
var callback = function (response) {};

$.get(url, data, callback);
$.post(url, data, callback);

A
  • $ = “jQuery”
  • url = the url you’re making the request to
  • data = extra information added to the url as a query string or in the body
  • callback = do something with the response
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

responseText property

A
  • jQuery passing the data from the server response to the callback function of $.get()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

$(‘#load’).hide()

A
  • hides HTML element with the ID of “load”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

$(document).ready(function() {});

A
  • waits for all the html in a file to load into the browser before running any of the JavaScript inside it
  • required only when including JS in the head
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

$.each(array, function(index, value) {});

A
  • loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

$(‘#employeeList’).html(statusHTML)

$(‘#signup’).html(‘<p>Thanks for signing up!</p>’)

A
  • selects id and inserts HTML created with HTML
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
$('form').submit(function(evt) {
// event handler
evt.preventDefault();
// method
var url = $(this).attr('action');
var formData = $(this).serialize();
$.post(url, formData, function(response) {};
});
A
  • when visitor clicks the submit button, it’ll send off AJAX request
  • used with an event object to prevent the browser from responding normally to an event
  • e.g. it prevents a form from being submitted or loading a new web page when a page when a link is clicked
  • sets the URL to the “action” property of the form
  • creates a text string with standard URL-encoded notation of fields in an HTML form
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

$.ajax(url, settings);

$.ajax(url, {
data: formData,
type: 'POST',
success: function(response) {
$('#signup').html('<p>Thanks for signing up!</p>')
}
A
  • settings = JavaScript object containing settings that control how the AJAX request is made

$.ajax Advantages

  • has more options and provides greater control of the AJAX request
  • ability to set a timeout to control the maximum wait time for a response from a server
  • ability to send a username and password to resources that require user authenticaiton
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

$.get(‘missing.html’, function(data) {
$(‘#myDiv’).html(data);
}).fail(function(jqXHR) {
alert(jqXHR.statusText);

or

var errorMessage = '<p>Sorry! There's been an error.';
errorMessage += 'Please try again later.</p>';
$('#myDiv').html(errorMessage);
});
A
  • loads the contents of the file “missing.html” into an HTML tag on the page that has the ID of “myDiv”
  • fail method takes a single argument, a callback function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly