Skip to content

Instantly share code, notes, and snippets.

@charliegerard
Last active August 29, 2015 13:58
Show Gist options
  • Save charliegerard/10075493 to your computer and use it in GitHub Desktop.
Save charliegerard/10075493 to your computer and use it in GitHub Desktop.

#Day36 & 37

Morning exercise: https://gist.github.com/mathildathompson/10071564

When converting an array of string to an array of numbers, .map returns an altered array and .each returns the original array.


####Review JS To do App:

counter++ takes the current value of counter and returns the original ++counter adds 1 to counter and then returns it.


###Ajax

Same origin policy

Create platform to post on all social networks at the same time.

Having access with Javascript to the content from a different page

The ajax transation may take longer to finish then the code you write underneath so you need to specify to wait until the request is finished to execute the rest of the code.

Example:

var request = $.ajax({
        type: 'GET',
        url: '/random',
        success: function(){
            console.log("The request is finished");
            console.log("Your random number is: ", request.responseText); // This will work
            }
});
        
console.log("Your random number is: ", request.responseText); //This will fail.

This way is better:

$(document).ready(function(){
$('button').on("click", function(){
	var request = $.ajax({
		type: 'GET',
		url: '/random',
		success: function(){
			console.log("The request is finished");
			console.log("Your random number is: ", request.responseText);
		}
	 });
});
});

Even better way:

$(document).ready(function(){
    $('button').on("click", function(){
        $.ajax({
            type: 'GET',
            url: '/random',
            success: function(number){
                $('#number').text(number);
            }
        });
    });
});

#Day 37

Morning exercise: https://gist.github.com/wofockham/5a22e6aadb568a3c8e20

Bit field: http://en.wikipedia.org/wiki/Bit_field

learn jquery: http://learn.jquery.com/

jQuery plugins: https://plugins.jquery.com/tag/animation/

http://vimeo.com/25698808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment