WEBVTT 00:05.530 --> 00:11.980 In this video we're going to send the Ajax school using the data variable. 00:12.000 --> 00:18.670 So our this a very well at the moment contains all the details that we need to process everything in 00:18.670 --> 00:19.650 the page file. 00:19.780 --> 00:20.190 OK. 00:20.260 --> 00:26.380 Including the extra values likely departure longitudes and so on. 00:26.410 --> 00:36.560 So before we go ahead I'm just going to make a quick comment about the way we have written code here. 00:36.970 --> 00:45.100 So you might be wondering why we didn't run these functions simultaneously and then submitted the AJAX 00:45.100 --> 00:47.090 call right after. 00:47.410 --> 00:48.110 OK. 00:48.430 --> 00:56.740 So the problem with that is if you are sending a request like this then you wouldn't know what time 00:56.770 --> 01:00.650 exactly you would get the results of the request. 01:01.030 --> 01:01.870 OK. 01:02.350 --> 01:09.520 In other words you might fall in a situation where you send a request for the departure coordinates 01:09.940 --> 01:15.230 and another request for the destination coordinates but the school has already been sent. 01:15.520 --> 01:23.430 So you wouldn't have any chance of those values to the data variable before you send the AJAX call. 01:23.490 --> 01:23.880 OK. 01:23.920 --> 01:29.120 So that's why we had to wait for the status here. 01:29.460 --> 01:30.050 OK. 01:32.520 --> 01:36.080 And whether the state was OK or not. 01:36.090 --> 01:40.730 We had to wait and then run our code. 01:40.760 --> 01:41.440 All right. 01:41.670 --> 01:50.810 So now what you've done we have waited for the first request and we did the departure coordinates. 01:51.110 --> 01:52.360 OK. 01:52.580 --> 01:56.770 Or if the state it was not OK we just moved to this function. 01:56.840 --> 02:00.890 I do the same thing we had to wait for the searchers after the requests 02:05.040 --> 02:14.050 and then we run the code there and now we are ready to submit the form using AJAX. 02:14.190 --> 02:15.530 So we can do it twice. 02:15.540 --> 02:21.220 So we're going to do it in both conditions or both cases. 02:21.220 --> 02:27.290 So in the first case if the seizures is ok we'll guess the destination coordinates and then we will 02:27.570 --> 02:38.140 miss Mr. form so we're going to call a function going to call submits trip request. 02:39.170 --> 02:39.600 OK. 02:39.740 --> 02:43.580 So that's if this is OK if it's not OK we'll still say it's OK. 02:43.580 --> 02:46.080 The only difference is that we're going to have elements missing. 02:46.100 --> 02:47.500 OK. 02:47.510 --> 02:52.210 So now we're going to need to define this function 03:00.790 --> 03:09.730 so inside this function we will just have to just call this copy a previous Adra school from another 03:09.730 --> 03:10.270 file. 03:23.470 --> 03:24.550 For example 03:29.390 --> 03:29.730 OK 03:45.950 --> 03:51.980 so we are sending the age of school here to the Crips ph people 04:03.310 --> 04:05.020 that's all you want. 04:05.740 --> 04:07.320 OK. 04:07.990 --> 04:11.210 It's like please post the data is Kaulitz. 04:11.470 --> 04:14.890 Well we already know the data it's our data very well. 04:15.480 --> 04:16.110 OK. 04:16.330 --> 04:24.940 So if the goal is successful we're going to have a function to execute on if it's more successful then 04:24.940 --> 04:28.000 we're going to show an error message inside every message. 04:28.060 --> 04:35.530 And the idea of not Dave was Trippe message. 04:36.600 --> 04:39.140 OK I'm going to use the same Ajax here. 04:39.330 --> 04:39.660 So 04:42.370 --> 04:55.360 the the file is going to receive all our data and if everything is OK it's going to store the data in 04:55.360 --> 05:05.230 a new record in the cache trips table if there is a problem then it's going to return an error message. 05:05.550 --> 05:06.180 OK. 05:06.180 --> 05:14.770 So our function is going to check if you've got anything inside that data. 05:14.910 --> 05:18.750 You can call that return data instead of data. 05:18.750 --> 05:19.740 Call it anything you like 05:22.830 --> 05:27.130 so if return data. 05:27.660 --> 05:29.700 Then we go into 05:34.720 --> 05:40.300 place that error message inside the trip message 06:00.770 --> 06:04.300 otherwise we are going to do a few things. 06:04.370 --> 06:17.030 So first of all we're going to hide the model OK and then we go into resets of form because you might 06:17.030 --> 06:22.780 want to on another trip to see how we get to that later. 06:23.990 --> 06:24.780 OK. 06:25.220 --> 06:32.430 And also we will need to load the chips and show them on the page. 06:32.530 --> 06:32.950 OK. 06:33.080 --> 06:35.370 I'm going to have the new chip appearing there as well. 06:37.110 --> 06:38.980 I'm going to come back to this later. 06:41.880 --> 06:42.960 OK. 06:43.000 --> 06:43.220 So 06:46.140 --> 06:49.040 let's save this one now. 06:49.050 --> 06:52.070 Now we're going to go to the BHB file. {"threads":[{"position":2112937,"start":0,"end":12407129,"connection":"open"},{"position":12407130,"start":12407130,"end":24814258,"connection":"idle"}],"url":"https://a2.udemycdn.com/2017-02-12_16-24-12-0b1001310f326da79bcfbe6b2ec39305/WebHD_720p.mp4?nva=20190604183200&token=01dd0780bae2ad973c23e","method":"GET","port":443,"downloadSize":24814258,"headers":{"date":"Mon, 03 Jun 2019 03:32:23 GMT","content-type":"binary/octet-stream","content-length":"24814258","connection":"close","etag":"\"26514e8bc23ca4dc64995142fe9c96cb\"","last-modified":"Fri, 10 Aug 2018 22:01:41 GMT","server":"AmazonS3","x-amz-id-2":"9y/e6pXTkmsx+cZqCPZKuZMCT4/goD/Ft9WkjX5fC6VVOtJ+47V49t4cQfcCSw03AnzK3UN811Q=","x-amz-replication-status":"COMPLETED","x-amz-request-id":"10ABEBEFB870F498","x-amz-storage-class":"INTELLIGENT_TIERING","x-amz-version-id":"LEDEnKV6I7PPremPQvpURwDz7.fcGh2p","access-control-allow-origin":"*","age":"128257","accept-ranges":"bytes"}}