What could be the reason that my JSON request is not functioning properly?

I am currently working on creating a movie search application. This project marks my first time delving into json and I'm facing some issues with my code. As of now, I have it set up and running smoothly on localhost through xampp. On submitting the form

$('.search-form').submit(function (evt) {
        // body...
        evt.preventDefault();
        var $searchBar = $('#search');
        var omdbApi = 'http://www.omdbapi.com/?';
        var movieSearchTerm = $searchBar.val();
        var searchData = {
            s:movieSearchTerm,
            r:'json'
    } 

Below is the callback function:

 function displayMovies(data) {
        // looping through each search result
        $.each(data.items,function(i,movie) {
        movieHTML += '<li class="desc">';
        // including movie title
        movieHTML += '<a href="' + movie.Title + '" class="movie-title">';
        // adding release year
        movieHTML += '<a href="' + movie.Year + '" class="movie-year">';
        // displaying movie poster
        movieHTML += '<img src="' + movie.Poster + '" class="movie-poster"></li>';
        $('#movies').html(movieHTML);
      }); // end each
      // movieHTML += '</li>'; 
    }
    $.getJSON(omdbApi, searchData, displayMovies);
});//end submit

Answer №1

r:json

Oops, a mistake was made.

You forgot to define a variable named json and the platform is expecting the value of r to be in the format of json.

Remember to enclose string literals with either " or '.

data.items

However, the JSON output does not include items, it actually has Search.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why is the UI Router controller failing to function properly after loading the view from the $templateCache?

I've been utilizing gulp-angular-templatecache to convert my filename.view.html files into a consolidated templates.js file. Afterwards, I use $stateProvider to define states and fetch the templates from $templateCache, including an abstract "root" s ...

The dynamic data graph generated by HIGHCHARTS Areaspline is not as effective as expected

I need help creating a Dynamic Areaspline graph, but the result is coming out strangely. Does anyone have any ideas on how to fix this and get a smooth series? Here is an example of the issue: http://jsfiddle.net/mchc59nb/1/ chart: { ...

Adjusting the size of images in real time

Currently, I am in the process of creating a Fluid grid style website and I am looking to decrease the size of all images by 75% when the screen is below 1280px, 50% at 800px, and so forth. Is there a way to achieve this using the IMG tag? My attempt so ...

How do useCases interact with each other within Clean Architecture principles in NodeJS?

I'm currently working on implementing Bob Martin's Clean Architecture in my project, and I have a question. How do use-cases interact with each other? For instance: In my project, there are entities for Department and Employee. The Department ...

JavaScript Canvas - Preserve Image Transparency

I have been trying to download a snapshot of a canvas using the code below: var strMime = "image/png"; var canvas = document.getElementsByTagName('canvas')[0]; var link = document.createElement("a"); link.href = canvas.toDataURL( ...

Ensuring the validity of an HTML form by including onClick functionalities for additional form elements

I am working on a form that I put together using various pieces of code that I found online. My knowledge of HTML and JavaScript is very basic. The form includes a button that, when clicked, will add another set of the same form fields. Initially, I added ...

What could be causing req.body to consistently come back as an empty object?

I am struggling with req.body always returning an empty object regardless of what I try. I have experimented with: var jsonParser = bodyParser.json(); and then including jsonParser in the function -> app.post('/api/get-last-project',jsonParser ...

Creating beautiful user interfaces with Material UI and React

I'm currently exploring how to integrate Material UI into my React project. After successfully installing the module, I attempted to create a custom button component. Here is my Button.js file: import React from 'react'; import FlatButton ...

Can you provide me with guidance on utilizing jq to filter a JSON output that contains a nested sub-key value?

Using jq, I am attempting to filter the most recent Docker Image version from a curl output. Here is what I have so far: Command curl | jq -r '(.[] | {digest, tags})' Output: Note: The output includes fictional values as real ones have been r ...

Tips for inserting characters at the cursor in a contenteditable element?

Is there a way to simulate typing a character in either JQuery or plain JavaScript? I am working with a contenteditable section where I need to intercept user input to replace certain characters (such as straight quotes with curly ones). While I have foun ...

Include a "remember me" feature in the Stripe form

I am currently working on an exciting project using Angular 6. Within my website, I have decided to integrate the Stripe payment system. However, I would like to incorporate a unique and default "remember me" feature offered by Stripe. <div id="card-e ...

Issues with special characters in Bootstrap table JSON files

Currently, I am populating a table on my website using the Bootstrap Table plugin and JSON data. However, I have noticed that some literals with accents are not displaying correctly on the web page. I have included the following meta tag in the head secti ...

Unregistering an event with AngularJS

Exploring the functions of a controller named MyCtrl: class MyCtrl { constructor($scope, $rootScope, ...) { this.$scope = $scope; this.$rootScope = $rootScope; this.doThis = _debounce(this.resize.bind(this), 300); ... ...

Utilizing AJAX and PHP to create a dynamic like button function

Is there a way to make the like number increase without refreshing the page when the like button is clicked? Here's my current code: <script type="text/javascript> jQuery(document).ready(function ($) { $('body').on( 'cli ...

Embed the parent component within the child component

I have two files called Recursive.vue and Value.vue. Initially, when Recursive is the parent component, mounting Recursive within itself works perfectly. Similarly, mounting Value within Recursive and then Value within itself also works fine. However, an ...

Obtaining a value from an array using Google App Script

Having some difficulties with the code snippet provided here. It might be a basic question, but I'm unable to figure out what's going wrong. The issue is that I'm trying to perform calculations on individual values in an array generated fro ...

Locating the exact position of a DOM node within the source document

Purpose In the process of creating a series of 'extractor' functions to identify components on a page using jsdom and nodejs, I aim to organize these identified 'component' objects based on their original placement within the page. Ch ...

Encountering an issue with the npm start command in my React application

After using npx create-react-app basic to create a React app, I navigated to the basic folder and attempted to start it with npm start. However, I encountered the following error: npm start <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

"Encountered a hiccup while trying to query a web service using Power BI - Oops! We hit a roadblock: Expression

Our web service generates JSON data, which we retrieve using jQuery REST calls and display in tables. The web service is written in C# WEBAPI and the code snippet looks like this: data = serializer.Serialize(rows); return Request.CreateResponse(HttpS ...

The code within the then() promise resolver function will always execute, regardless of whether the promise succeeds or

After clicking a button, I trigger a vuex action which returns an axios promise from the store. In my component, I only want to reset form fields when the action is successful. However, currently the form fields are always reset, even if the promise fails. ...