- Write about something you learned this week.
Using APIs. I used a Pokemon API to make a website where two pokemon appear and their attack stats are compared to say which one would win.
- Why would you use something like the load event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?
The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading. To execute anything post document load, we fire these events. One disadvantage is that it won't wait for an image to load, so you have to do something else about that. An alternative would be to use a setTimeOut. Another is DOMContentLoaded.
- What are the advantages and disadvantages of using Ajax?
Advantages of AJAX
AJAX Concept
Before you starting AJAX you'll need to have a strong knowledge of JavaScript. AJAX is not a difficult, you can easy implement AJAX in a meaningful manner. Some IDE are help us to implement AJAX.
Speed
Reduce the server traffic in both side request. Also reducing the time consuming on both side response.
Interaction
AJAX is much responsive, whole page(small amount of) data transfer at a time.
XMLHttpRequest
XMLHttpRequest has an important role in the Ajax web development technique. XMLHttpRequest is special JavaScript object that was designed by Microsoft. XMLHttpRequest object call as a asynchronous HTTP request to the Server for transferring data both side. It's used for making requests to the non-Ajax pages.
Asynchronous calls
AJAX make asynchronous calls to a web server. This means client browsers are avoid waiting for all data arrive before start the rendering.
Form Validation
This is the biggest advantage. Form are common element in web page. Validation should be instant and properly, AJAX gives you all of that, and more.
Bandwidth Usage
No require to completely reload page again. AJAX is improve the speed and performance. Fetching data from database and storing data into database perform background without reloading page.
Disadvantages of AJAX
1. AJAX application would be a mistake because search engines would not be able to index an AJAX application.
2. Open Source: View source is allowed and anyone can view the code source written for AJAX.
3. ActiveX requests are enabled only in Internet Explorer and newer latest browser.
4 The last disadvantage, XMLHttpRequest object itself. For a security reason you can only use to access information from the web host that serves initial pages. If you need to fetching information from another server, it's is not possible with in the AJAX.
- Explain how JSONP works (and how it's not really Ajax).
JSONP (acronym for JavaScript Object Notation with Padding) is a common method to retrieve data from another domain and bypass CORS (Cross Origin Resource Sharing) rules.
An overview of JSONP base on personal experience
I have used JSONP as a work around to get data by wrapping the response data in JSON format with a function callback set in query string as parameter and setting the callback as an object property of ajax object.
** Note, I was using jQuery library when implementing AJAX with JSONP
I’ve also heard of CORS as a set of rules regarding retrieving and transferring data or assets from 3rd parties or different domains from a client. This strictly applies to XMLHttpRequest for security reasons. Making HTTP Requests with XMLHTTPRequest object will only let us make request to our own domain and restricts us from different domain, thus, JSONP was created as a way to bypass this rule.
How does JSONP work?
After reading further, implementation of JSONP differ from JavaScript libraries to the actual native JavaScript. In native JavaScript, JSONP requests aren’t dispatched with XMLHttpRequest object, rather, a script tag is added to the DOM, targeting its src attribute with the url. Reason is script tag does not have limitation to which domains it can retrieve its scripts from. Also, since JavaScript has a global scope, we can reference a function to handle incoming JSON data from a 3rd party api url and link that to our application. While, in JavaScript libraries such as jQuery, it automatically generate callback and clean up any inserted script tags unto the DOM.
If you copy & paste the url below, this will return a simple quote formatted in JSON
http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json
While this url will return the same result except JSON data will be wrapped with a function since we explicitly specify format as jsonp and gave it a callback function
http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=processQuote
When this loads unto our application from script tag, the given callback name (function name) will get registered unto the global scope and will be available for us to use throughout our application.
JSONP limits us with just retrieving GET data. It does not let us create, update, or delete CRUD data. That’s why its just a work around but it does have its advantages. For example, retrieving simple data from a weather api, etc. If you want to take advantage of these other HTTP methods, then its best to build your own simple API Server.
- Explain Ajax in as much detail as possible.
AJAX = Asynchronous JavaScript and XML.
AJAX is a technique for creating fast and dynamic web pages.
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.
Classic web pages, (which do not use AJAX) must reload the entire page if the content should change.
Examples of applications using AJAX: Google Maps, Gmail, Youtube, and Facebook tabs.
It is a technique used in order to send and retrieve data in the background without refreshing the webpage.
- What does it mean when we talk about time complexity of an algorithm?
Time complexity is a concept in computer science that deals with the quantification of the amount of time taken by a set of code or algorithm to process or run as a function of the amount of input. In other words, time complexity is essentially efficiency, or how long a program function takes to process a given input.
- What are the three laws of recursion algorithm?
Like the robots of Asimov, all recursive algorithms must obey three important laws: A recursive algorithm must call itself, recursively. A recursive algorithm must have a base case. A recursive algorithm must change its state and move toward the base case.
- How do you see yourself growing as a web developer?
I'm still unsure. I don't like making websites that have only aesthetic and commercial properties. I like complex applications and i still can't code them so I still need to learn a lot more.