Skills and jobs created asynchronously#5
Merged
tannerwelsh merged 5 commits intomasterfrom Oct 30, 2014
Merged
Conversation
Organization! Ohhhhh yeah.
Adds dependency on the jQuery library (loaded via the CDN). Adding a skill using the form on the résumé show page now uses AJAX to allow users to add skills without requiring a full page refresh. Sending an AJAX request to create a new resource generally involves writing JavaScript code that implements the following steps: - Bind to the "submit" event of a form - Prevent the form from doing what it would normally do (usually: send an HTTP POST request) - Send an XMLHTTPRequest with the "POST" method, passing along the form data in the request body (in this case, we're using jQuery's `$.post` method to abstract over the logic of sending a request) - Add an event listener to handle the response when it comes back (this is the asynchronous part: we give the browser a function and say "hey, whenever you hear back from the server, run this code.")
By sending the all of the form data (using jQuery's .serialize() function), the server can create a new skill from the form data whether it is sent via AJAX or a regular HTTP POST request. This is useful in case the user has disabled JavaScript. To determine what kind of response to send back, we call `.xhr?` on the `request` object, which returns true if the server is responding to an AJAX request. That way, we can send back whatever the JavaScript wants (in this case it is a snippet of HTML).
Better to break up the work into separate functions with explicit purposes. +1 code style points.
Same deal as with skills, now jobs can be added asynchronously too.
tannerwelsh
added a commit
that referenced
this pull request
Oct 30, 2014
Skills and jobs created asynchronously
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This branch add supports for the following features:
Note that the JavaScript introduced degrades gracefully, meaning that if a user has disabled JavaScript in their browser, the site will still function as expected. New skill and job forms will be sent via HTTP, and the page will refresh showing the updated information.
This branch introduces a dependency on jQuery, a popular and powerful JavaScript library.