Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make the AJAX request Now let\'s do the same thing in JavaScript. As you can see

ID: 3854959 • Letter: M

Question

Make the AJAX request Now let's do the same thing in JavaScript. As you can see, a fair bit of code is already there. Apart from the first line where you should have added your access token, you shouldn't modify anything above line 32. If you're not sure what to do during this step, look at the AlAX demol did last week. In the requestsearch function, you will need to create a requestsettings object that contains our request settings, and then use the jouery.aj function to send the request. The settings object can contain many things (see the jQueny documentation for a complete list. In our case, we need to call the searchsuccess function when the response is a success o call the searchError function when the response is an error o set the query string parameters. You can either append them to the URL, or set the data attribute in the requestsetting object. The data attribute should be an object that contains key/value pairs, like this: var requestsettings data kl t vi, k21 v2 The keys and values should match what is described in the Yolp API e set the Authorization header (with the same value as in step 2), using the headers attribute in the settings. The headers attribute has the same structure as data e, an object containing key value pairs, Once you set the correct values for the data (term, latitude and longitude) and headers (Authorization), the last thing to add to this function is the code that sends the request, with the jouery.ajax() function. The first parameter of that request should be the url (which is conveniently stored for you in the SEARCH ENDPOINT variable), and the second should be the request settings. At this point, if you open your Chrome developer tools, look at the Network tab, and then click on the search button, then you see that some requests are send (or have errors in the console if something is wrong).

Explanation / Answer

Find the below code which needs to be appended

function requestSearch(searchTerm, coordinates) {

$.ajax({
url: SEARCH_ENDPOINT,
type: "get", //send it through get method
data: {

searchTerm: searchTerm,
coordinates: coordinates

}
});


}

function searchSuccess(data, textStatus, jqXHR) {
console.log("SUCCESS " + "Data value :" + data + " textStatus value " + textStatus + " " + jqXHR);
}

function searchSuccess(data, textStatus, jqXHR) {
console.log("FAILURE " + "jqXHR value :" + jqXHR + " textStatus value " + textStatus + "data " + data);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote