w6d5 Flashcards
What does margin:auto need in order to work?
A width property.
What does javascript:void(0) do?
It fires the corresponding event but does not execute the default action (similar to preventDefault());
How can we easily toggle a class using jQuery?
toggleClass(altClass);
What is a tool to check the integrity of your HTML?
W3 validator.
How can we find classes whose name matches a string?
$towers.find(“li[class*=’disk’)”)
What is a useful way to see what exactly is going on with your CSS layout?
Use colored backgrounds.
What is an XHR?
XMLHttpRequest
What are the two ways to call $.ajax()
Pass is a configuration object, or a URL and an optional configuration object.
See an example of how to properly create an AJAX object. How is the callback being used? How many are there and why?
The 2 callback functions (one for error and another for success) are defined and then added as values for the success/failure keys in the configuration object.
What is a quick way to define the success & error AJAX callbacks?
Make them anonymous functions on the configuration object.
In what data format do servers typically respond to an XHR, despite the name?
JSON
What are the key methods to utilize JSON objects?
JSON.stringify(), JSON.parse(), jQuery.parseJSON
What are convenience methods for AJAX?
Each takes a URL, an optional data object, and an optional callback for a successful request (note there is NO error handling)
$.get( ‘/data/people.html’, function( html ){
$( ‘#target’ ).html( html );
});
$.post( ‘/data/save’, { name: ‘Rebecca’ }, function( resp ) {
console.log( resp );
});
How can we pass (form) data t an AJAX request?
By giving it as the ‘data’ key, after serializing it in a query string format:
$( ‘form’ ).submit(function( event ) {
event.preventDefault();
var form = $( this );
$.ajax({ type: 'POST', url: '/data/save', data: form.serialize(), dataType: 'json', success: function( resp ) { console.log( resp ); } }); });
When we capture the result of $.ajax() in a variable, what is that called?
It is called a jqXHR