0% found this document useful (0 votes)
38 views

Events: Insertion Inside

The document provides examples of DOM manipulation using jQuery, making AJAX requests in jQuery, and working with JSON data. It shows how to insert elements into the DOM, make GET and POST requests to retrieve JSON data, and access and modify values in JSON arrays and objects.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Events: Insertion Inside

The document provides examples of DOM manipulation using jQuery, making AJAX requests in jQuery, and working with JSON data. It shows how to insert elements into the DOM, make GET and POST requests to retrieve JSON data, and access and modify values in JSON arrays and objects.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Events

target

relatedTarget

pageX

pageY

which

metaKey

Dom Manip
Insertion inside
$( "<p>Test</p>" ).prependTo( ".inner" );
$( "h2" ).prependTo( $( ".container" ) );

Ajax
$.ajax({
// The URL for the request
url: "post.php",
// The data to send (will be converted to a query string)
data: {
id: 123
},
// Whether this is a POST or GET request
type: "GET",
// The type of data we expect back
dataType : "json",
})

// Code to run if the request succeeds (is done);


// The response is passed to the function
.done(function( json ) {
$( "<h1>" ).text( json.title ).appendTo( "body" );
$( "<div class=\"content\">").html( json.html ).appendTo( "body" );
})
// Code to run if the request fails; the raw request and
// status codes are passed to the function
.fail(function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
})

// Code to run regardless of success or failure;


.always(function( xhr, status ) {
alert( "The request is complete!" );
});

JSON
{} = object
[] = array
name:value,name:value

Eg.
var employees = [
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter","lastName": "Jones"}
];

usage
employees[0].firstName + " " + employees[0].lastName;

employees[0]["firstName"] + " " + employees[0]["lastName"];

modification
employees[0].firstName = "Gilbert";
employees[0]["firstName"] = "Gilbert";

You might also like