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

Now let\'s do the same thing in JavaScript. As you can see, a fair bit of code i

ID: 3854915 • Letter: N

Question

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 taken, you shouldn't modify anything above line 32. If you're not sure what to do during this step, look at the AJAX demo I did last week. In the request Search function, you will need to create a requestSettings object that contains our request settings, and then use the jQuery.ajax() function to send the request. The settings object can contain many things (see the jQuery documentation for a complete list). In our case, we need to: call the searchSuccess function when the response is a success call the searchError function when the response is an error set the query string parameters. You can either append thorn 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: {k1: v1, k2: v2}, ... The keys and values should match what a described in the Yelp API 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. i.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 jQuery.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 a wrong).

Explanation / Answer

Find the below required code as per the problem statement asked

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);


}

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