|
1 | | -CHAPTER 3 |
| 1 | +CHAPTER 3 |
2 | 2 | -------- |
3 | 3 |
|
4 | 4 | Getting Data from Backend Using jQuery and Parse |
@@ -105,7 +105,7 @@ another object; for example: |
105 | 105 | "title": "Get your mind in shape!", |
106 | 106 | "votes": 9, |
107 | 107 | "comments": [ |
108 | | - "nice!", |
| 108 | + "nice!", |
109 | 109 | "good link" |
110 | 110 | ]}, { |
111 | 111 | "title": "Yet another post", |
@@ -271,7 +271,7 @@ this: |
271 | 271 | /01-bootstrap |
272 | 272 | -index.html |
273 | 273 | /css |
274 | | - -bootstrap.css |
| 274 | + -bootstrap.css |
275 | 275 | -bootstrap.min.css |
276 | 276 | ... (other files if needed) |
277 | 277 | /js |
@@ -622,14 +622,14 @@ technologies. |
622 | 622 | The idea of this weather application is to show you an input field for |
623 | 623 | the city name and buttons for metric and imperial systems. The first page of the Weather application has the input field for the city name and two buttons for metric and imperial forecasts (Figure 3-1). |
624 | 624 |
|
625 | | - |
| 625 | + |
626 | 626 |
|
627 | 627 | ***Figure 3-1.** Weather App has a text input field and two button for the forecasts.* |
628 | 628 |
|
629 | 629 | Once you enter the city name and click one of the buttons, the app will fetch the |
630 | 630 | forecast from OpenWeatherMap. Depending on what button is pressed, the app will fetch the forecast in metric (C) or imperial (F) degrees. For example, I like in the heart of tech innovation, San Francisco and we use imperial F degrees here so my result will be similar to the one shown in Figure 3-2. The forecast will be for several days with a 3-hour difference between predictions. |
631 | 631 |
|
632 | | - |
| 632 | + |
633 | 633 |
|
634 | 634 | ***Figure 3-2.** Weather App show the forecast for San Francisco.* |
635 | 635 |
|
@@ -724,7 +724,7 @@ for the buttons: |
724 | 724 | <input type="button" class="btn-primary btn btn-metric" value="Get forecast in metric"/> |
725 | 725 | <div class="span6 offset1"> |
726 | 726 | <input type="button" class="btn-danger btn btn-imperial" value="Get forecast in imperial"/> |
727 | | - </div> |
| 727 | + </div> |
728 | 728 | <div class="span3"> |
729 | 729 | <p id="info"></p> |
730 | 730 | </div> |
@@ -886,17 +886,17 @@ the `index.html` file: |
886 | 886 | <p>Enter city name to get the weather forecast</p> |
887 | 887 | </div> |
888 | 888 | <div class="span6 offset1"> |
889 | | - <input class="span4" type="text" placeholder="Enter the city name" |
| 889 | + <input class="span4" type="text" placeholder="Enter the city name" |
890 | 890 | id="city-name" value=""/> |
891 | 891 | </div> |
892 | 892 | </div> |
893 | | - |
| 893 | + |
894 | 894 | <div class="row"> |
895 | 895 | <div class="span6 offset1"> |
896 | 896 | <input type="button" class="btn-primary btn btn-metric" value="Get forecast in metric"/> |
897 | 897 | <div class="span6 offset1"> |
898 | 898 | <input type="button" class="btn-danger btn btn-imperial" value="Get forecast in imperial"/> |
899 | | - </div> |
| 899 | + </div> |
900 | 900 | </div> |
901 | 901 |
|
902 | 902 | <div class="row"> |
@@ -944,13 +944,13 @@ Parse |
944 | 944 | Supplemental video which walks you through the implementation and |
945 | 945 | demonstrates the project: <http://bit.ly/1SU8imX>. |
946 | 946 |
|
947 | | -[Parse](http://parseplatform.org) (http://parseplatform.org) is a platform which is a collection of server and client libraries that offer a feature-rich backend. With Parse server, developers can focus on building their client apps (web or mobile) because they'll have a substitute for a database and a server. In other words, with Parse, there's no need to build your own server or to maintain a database! |
| 947 | +[Parse](http://parseplatform.org) (http://parseplatform.org) is a platform which is a collection of server and client libraries that offer a feature-rich backend. With Parse server, developers can focus on building their client apps (web or mobile) because they'll have a substitute for a database and a server. In other words, with Parse, there's no need to build your own server or to maintain a database! |
948 | 948 |
|
949 | 949 | Parse started as means to |
950 | 950 | support mobile application development. Nevertheless, with the REST API |
951 | 951 | and the JavaScript SDK, Parse can be used in any web and desktop |
952 | 952 | applications for data storage (and much more), making it ideal for rapid |
953 | | -prototyping. |
| 953 | +prototyping. |
954 | 954 |
|
955 | 955 | To create a local instance of Parse simply install two npm modules: `parse-server` and `mongodb-runner` using npm: |
956 | 956 |
|
@@ -973,7 +973,7 @@ parse-server --appId APPLICATION_ID --masterKey MASTER_KEY --databaseURI mongodb |
973 | 973 | ``` |
974 | 974 |
|
975 | 975 |
|
976 | | -Create your backend Parse server application. Feel free to use your own values for `appId` and `masterKey`. Copy the Application ID, master key into the front end project files such as 03-parse-sdk/app.js because you'll need to use the exact the same value on the front end in order to be able to access your backend server. In other words, we'll need these keys to access our data collection at Parse. |
| 976 | +Create your backend Parse server application. Feel free to use your own values for `appId` and `masterKey`. Copy the Application ID, master key into the front end project files such as 03-parse-sdk/app.js because you'll need to use the exact the same value on the front end in order to be able to access your backend server. In other words, we'll need these keys to access our data collection at Parse. |
977 | 977 |
|
978 | 978 | We'll create a simple application that will save values to the |
979 | 979 | collections using the Parse JavaScript SDK. The final solution is in the 03-parse-sdk folder. Our application will |
@@ -1070,7 +1070,7 @@ Parse server (you define them when you start the Parse server): |
1070 | 1070 |
|
1071 | 1071 | ```js |
1072 | 1072 | const parseApplicationId = 'APPLICATION_ID' |
1073 | | -const parseJavaScriptKey = 'MASTER_KEY' |
| 1073 | +const parseJavaScriptKey = 'MASTER_KEY' |
1074 | 1074 | ``` |
1075 | 1075 |
|
1076 | 1076 | Because we've included the Parse JavaScript SDK library, we now have |
@@ -1080,9 +1080,9 @@ keys, and create a reference to a `Test` collection: |
1080 | 1080 | ```js |
1081 | 1081 | Parse.initialize(parseApplicationId, parseJavaScriptKey) |
1082 | 1082 | Parse.serverURL = 'http://localhost:1337/parse' |
1083 | | -``` |
| 1083 | +``` |
1084 | 1084 |
|
1085 | | -Next, create the collection object. It's like a model for our data. The name is `Test` but it can be any string value. |
| 1085 | +Next, create the collection object. It's like a model for our data. The name is `Test` but it can be any string value. |
1086 | 1086 |
|
1087 | 1087 | ```js |
1088 | 1088 | const Test = Parse.Object.extend('Test') |
@@ -1219,20 +1219,20 @@ you should see the proper message with the newly created ID. Parse |
1219 | 1219 | automatically creates object IDs and timestamps, which will be very |
1220 | 1220 | useful in our Message Board application. |
1221 | 1221 |
|
1222 | | - |
| 1222 | + |
1223 | 1223 |
|
1224 | 1224 | ***Figure 3-4.** Save button will send the object to the backend which will save it to the database.* |
1225 | 1225 |
|
1226 | 1226 | If you press on the Get object (green button), then you'll get all the objects which are stored in the database. How to confirm that this data is actually store in the database and won't disappear when we close the browser? Simply, close the browser and open it again. If still not convinced, use Mongo shell/REPL or Compass (Figure 3-4) to go to the local MongoDB database instance and the Test collection. There will be the data just sitting and looking at you. |
1227 | 1227 |
|
1228 | 1228 |
|
1229 | | - |
| 1229 | + |
1230 | 1230 |
|
1231 | 1231 | ***Figure 3-5.** Compass shows in MongoDB the data which was sent from the browser.* |
1232 | 1232 |
|
1233 | 1233 | Parse also has thorough instructions for the various parts of platform including its server and clients libraries: <http://docs.parseplatform.org>. You can deploy parse server into cloud or your own data center. Parse supports containers too. |
1234 | 1234 |
|
1235 | | -With Parse we can use browser JavaScript, one command-line (parse-server) and wheyee! We can save to the database straight from the browser!!! |
| 1235 | +With Parse we can use browser JavaScript, one command-line (parse-server) and wheyee! We can save to the database straight from the browser!!! |
1236 | 1236 |
|
1237 | 1237 | Let’s move on to the Message Board app. |
1238 | 1238 |
|
@@ -1247,12 +1247,12 @@ and a send button. We need to display a list of existing messages and be |
1247 | 1247 | able to submit new messages. We'll use Parse as a back end for now, |
1248 | 1248 | and later switch to Node.js with MongoDB. |
1249 | 1249 |
|
1250 | | - |
| 1250 | + |
1251 | 1251 |
|
1252 | 1252 | ***Figure 3-3.** Save button will send the object to the backend which will save it to the database.* |
1253 | 1253 |
|
1254 | 1254 |
|
1255 | | - |
| 1255 | + |
1256 | 1256 |
|
1257 | 1257 | ***Figure 3-4.** Get button will fetch the all objects form the backend.* |
1258 | 1258 |
|
@@ -1323,7 +1323,7 @@ local `app.js`, local minified Twitter Bootstrap, and custom stylesheet |
1323 | 1323 | <script src="js/app.js" type="text/javascript" language="javascript" ></script> |
1324 | 1324 | <link href="css/bootstrap.min.css" type="text/css" rel="stylesheet" /> |
1325 | 1325 | <link href="css/style.css" type="text/css" rel="stylesheet" /> |
1326 | | - <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 1326 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
1327 | 1327 | </head> |
1328 | 1328 |
|
1329 | 1329 | The body element will have typical Twitter Bootstrap scaffolding elements |
|