Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/login', function (req, res) {
- var username = req.body.username; // etc...
- if (username === "George" && password === "cat") {
- res.json({message : "success"});
- } else {
- res.json({message : "fail"});
- }
- });
- app.post('/login', function (req, res) {
- var username = req.body.username; // etc...
- if (username === "George" && password === "cat") {
- res.json({status: 200, message : "success"});
- }
- else {
- res.json({status: 401, message : "fail"});
- }
- });
- $.post( "/login", function(loginData) {
- })
- .done(function(data) {
- if(data.status === 200) {
- //logged in
- } else {
- //logged out
- }
- })
- .fail(function() {
- //error (bad connection)
- });
- $('#some-button').on('click', function() {
- //lets go make a request with some ajax call
- // lets say ajax call fails and responds with something like this:
- var error = {
- message: 'Could not retrieve data.',
- code: 403
- };
- //We can build a string of html, add the error fields to the html, and add that html to our document like so.
- var errorHtml = "<div class='error'><h3>Sorry, an error has occured.</h3><p>Message: _message</p><p>Code: _code</p></div>"
- .replace('_message', error.message)
- .replace('_code', error.code)
- // Add to document
- $('#error').html(errorHtml)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement