Be sure to verify any empty responses from the omdnapi

I am trying to use the omdbapi to gather movie information, and while I can retrieve data for valid movie titles, I want to display a message when the title entered does not exist. Can someone help me identify what is causing the issue in my code?

$scope.searchMovie= function(){
      $http.get('http://www.omdbapi.com/?t='+$scope.name+'&y='+$scope.year+'').success(function (response) {
        var len=response.length;
        if(len === null)
        {
            alert("No records found!");
        }
        else{
        $scope.movieSearch=response;
        }

      });
  };

Answer №1

When making an API call, the response will include a "Response" field. This field can be used to determine if the requested movie was found (response.Response=="True") or not (response.Response=="False").

Here's a simple example:

$scope.searchMovie= function(){
      $http.get('http://www.omdbapi.com/?t='+$scope.name+'&y='+$scope.year+'').success(function (response) {
        console.log(response);
        if (response.Response == "False")
        {
            alert("No records found!");
        }
        else if (response.Response == "True")

        }

      });
  };

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

Is Joomla.submitbutton('module.apply') causing the page to refresh?

The <em>Joomla.submitbutton('module.apply')</em> function causes the page to reload. I attempted to use it with ajax, but the page still reloads. Is there a way to utilize this function with ajax without refreshing the page? Thank yo ...

Adding inherent worth to individual instances within the Play JSON library

I have the following setup: sealed trait State case object Modified extends Status case object NotModified extends Status case class Post(content:String, state:State) To use Play Json formatting, I believe I need something like this (without using a com ...

Is there a way to categorize items from various arrays together?

I've successfully grouped child objects with parent objects using a concise example available on Plunker The methodology of nesting objects in one array makes perfect sense to me. Now, I'm interested in utilizing two distinct scope arrays for de ...

An error occurred while attempting to parse a JSON string using the Jackson library

Below is the JSON data I am attempting to parse utilizing the Jackson Java library. It represents a Vector of BackgroundShapes, where BackgroundShape subclasses include: BGRectangle BGCircle Within this JSON snippet, there are 2 BGRectangles, but it ma ...

Tips on customizing autocomplete to display results fetched via ajax

I created a basic text box for users to input information. Using AJAX, I send this information to a PHP script to retrieve results. The results are then displayed in a DIV beneath the input box. However, I am struggling to update the autocomplete suggestio ...

Selenium encountered an error when trying to execute the 'querySelector' function on the document. The selector provided, my_selector, is not recognized as a valid selector

Whenever I run this code: document.querySelector(my_selector) using selenium, an error is thrown: Failed to execute 'querySelector' on 'Document' my_selector is not a valid selector my_selector is definitely a valid selector that func ...

Concealing Enclosures in Jade - AngularJS Syntax

Struggling with writing this in Jade, specifically the .get() function is giving me trouble. <li ng-repeat="breadcrumb in breadcrumbs.get() track by breadcrumb.path" ng-class="{ active: $last }"></li> Seen from: https://github.com/ianwalter/n ...

Is there a way to continuously iterate through arrays in Firebase to make updates to object properties?

I am currently developing an inventory management application using AngularJS, Firebase, and the AngularFire library. One issue I'm facing is updating the unit number when a user performs an Import/Export action. I am unsure of how to retrieve the ...

Tips for preserving component state during page rerenders or changes

I created a counter with context API in React, and I'm looking for a way to persist the state even when the page is changed. Is there a method to store the Counter value during page transitions, similar to session storage? My app utilizes React Router ...

SWR Worldwide Settings

I am trying to configure a global SWRConfig in my Next.js application. In my _app.js file, I have the following setup: import '@/styles/bootstrap.min.css'; import "@/styles/globals.css"; import Layout from "@/components/Layout"; import { SWRConfi ...

There appears to be a syntax error in the Values section of the .env file when using nodejs

I have been working on implementing nodemailer for a contact form. After researching several resources, I came across the following code snippet in server.js: // require('dotenv').config(); require('dotenv').config({ path: require(&apos ...

What is the best way to rotate a group in ThreeJS while keeping its center as the pivot

I am currently attempting to construct a functioning Rubik's Cube using ThreeJS. However, I have encountered an issue with rotating the sides. To build the Rubik's Cube, I am adding individual smaller cubes in this manner: const rubiksCube = new ...

Dispose the inputpicker filter after setting the value

I am currently utilizing the "Jquery inputpicker plugin" for creating dropdown menus. More information about this plugin can be found here. To initialize my dropdown, I use the following code: $('#test').inputpicker({ data:[ {value:"1 ...

What is the best way to link my "dynamic sub-component" with AngularJS?

While I have a solid grasp on the fundamentals of AngularJS and can create basic CRUD applications, when it comes to applying this knowledge to real-world scenarios, I find myself struggling with how to integrate the concepts effectively. One specific cha ...

Modify the CSS of one div when hovering over a separate div

I've been working on a simple JavaScript drop-down menu, and it's been functioning correctly except for one issue. When I move the mouse out of the div that shows the drop-down menu, it loses its background color. I want the link to remain active ...

Display the count of ng-repeat items beyond its scope

Currently, I am looping through a list of nested JSON objects in this manner: <div ng-repeat='item in items'> <ul> <li ng-repeat='specific in item'>{{specific}}</li> </ul> </div> I want to ...

Convenient Ways to Implement a Switch Statement in an AngularJS Controller

Can you guide me on implementing a Switch Statement in an angularJS Controller? Here is the code snippet I am working with: <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></sc ...

What is the best way to update the return value of a filter in AngularJS?

My filter relies on the result of the service.show() function: angular.module('util') .filter('formatMoney', ['accounting', 'service', function (accounting, service) { return function (number) { ...

Unity of MEAN Assemblage

My current project involves working with the MEAN stack, particularly using MEAN.js. Although the documentation provides a good explanation of everything, I am facing a challenge when it comes to associating one entity or Model with another. To give an ex ...

We need to display JSON data from a URL onto an HTML page within a table format

Could someone assist me with fetching JSON data from a URL Link on Amazon AWS and displaying it in an HTML table? I am a novice at this, so please explain it easily. Below you can see the HTML code, JS code, and sample information that I would like to ex ...