External API GET request using jQuery

0 votes

I am using the IMDb API v2.0 located here and I decided to test it. I can't. I think it's beacuse of cross-browser AJAX request from external sites.. but I don't know any other way. For example, here's a test at imdbapi avatar

See? Here's my code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />


    <title>IMDB api</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>

    <script type="text/javascript">
    $(document).ready(function()
{
    $('#movie').keyup(function() {

       var yourMovie = $("#movie").val();
  $("#debug").append("You are searching for ... "+yourMovie+"\n");

dataString = "t=Avatar";

$.ajax({
type: "GET",
url: "http://www.imdbapi.com/",
cache: false,
data: dataString,

success: function(html){
//$("#more").after(html);
alert("Success!");
}

});
});
});
</script>

</head>
<body>


<form action="#" method="get" enctype="text/html" >
<input type="text" id="movie" maxlength="50" />

</form>

<div id="other">
  Trigger the handler
</div>
<br />
<textarea id="debug" style="width: 500px;height:150px;border:1px solid black;font-face:typewriter;"></textarea><br />
<textarea id="more" style="width: 500px;height:150px;border:1px solid red;font-face:typewriter;"></textarea>

</body>
</html>

I am using Google Chrome.

Here's what worked for me:

    <script type="text/javascript">
    $(document).ready(function()
{
    $('#movie').keyup(function() {

       var yourMovie = $("#movie").val();
  $("#debug").append("You are searching for ... "+yourMovie+"\n");

dataString = "callback=?&t=Avatar";

$.getJSON('http://www.imdbapi.com/', dataString, function(html){
//$("#more").after(html);
alert("Success!");
});


});
});
</script>

Jun 3, 2022 in JQuery by Edureka
• 13,670 points
212 views

1 answer to this question.

0 votes
  • url

    Type: String

    A string containing the URL to which the request is sent.

  • data

    Type: PlainObject or String

    A plain object or string that is sent to the server with the request.

  • success

    Type: FunctionPlainObject data, String textStatus, jqXHR jqXHR )

    A callback function that is executed if the request succeeds. Required if dataType is provided, but you can use null or jQuery.noop as a placeholder.

  • dataType

    Type: String

    The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).

answered Jun 3, 2022 by Edureka
• 13,670 points

Related Questions In JQuery

0 votes
0 answers

External API GET() request using jQuery

I am using the IMDb API v2.0 located here ...READ MORE

Jun 1, 2022 in JQuery by Edureka
• 13,670 points
371 views
0 votes
1 answer

How to import jQuery UI using ES6/ES7 syntax?

Hii, Add a alias in webpack config: resolve: { ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
7,366 views
0 votes
1 answer

How can I implement my own $(document).ready functionality without using jQuery?

Hello @kartik,  There are three options: If script is the last ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
1,301 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
41,505 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,510 points
973 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
14,128 views
0 votes
1 answer

Uncaught Error: Bootstrap's JavaScript requires jQuery

Hello @kartik, You have provided wrong order for ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,880 points
22,373 views
0 votes
1 answer

How to make Bootstrap popover Appear/Disappear on hover instead of click?

Hello @kartik, Set the trigger option of the popover to hover instead ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,880 points
2,944 views
0 votes
1 answer

Get selected value of a dropdown's item using jQuery

Use the jQuery: selected selector in combination ...READ MORE

answered Jun 3, 2022 in JQuery by Edureka
• 13,670 points
9,130 views
0 votes
1 answer

How to change color of SVG image using CSS (jQuery SVG image replacement)?

Edit your SVG file, add fill="currentColor" to ...READ MORE

answered Jun 1, 2022 in JQuery by Edureka
• 13,670 points
21,404 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP