RESTfull web service display info on page, using visual studio 2015

Sean Li

I have trouble with building a web service can read information of NBA players from a txt file and then display it on the web page.

Firstly, I build a class in the Models folder.

namespace zuoye4.Models
{
    public class Players
    {
        public string Registration_ID { get; set; }
        public string Player_name { get; set; }
        public string Team_name { get; set; }
        public DateTime Date_of_birth { get; set; }
    }
}

Secondly I create a Controller to read file and add all players to an list. I also define a GetAllPlayers method to return the list.

Testing shows thisenter image description here

Then I create a html page to display the list. Here is my code.

<!DOCTYPE html>
<html>
<head>
    <title>PLALYERS</title>
    <meta charset="utf-8" />
</head>
<body>
    <div>
        <h2>All Players</h2>
        <ul id="players" />
    </div>

    <div>
        <h2>Search by ID</h2>
        <input type="text" id="prodId" size="5" />
        <input type="button" value="Search" onclick="find();" />
        <p id="product" />
    </div>

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
    <script>
        var uri = 'api/Players';

    $(document).ready(function () {
      // Send an AJAX request
      $.getJSON(uri)
          .done(function (data) {
            // On success, 'data' contains a list of players.
            $.each(data, function (key, item) {
              // Add a list item for the player.
                $('<li>', { text: formatItem(item) }).appendTo($('#playerList'));
            });
          });
    });

    function formatItem(item) {
        return item.Registration_ID + ': $' + item.Player_name;
    }
  </script>

</body>
</html>

It should shows something like this. enter image description here

But I get nothing.enter image description here

What I've done wrong???

Here is the tutorial follow. https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Alexandru Marculescu

You seem to be appending the players list item to an element with id "playerList":

$('<li>', { text: formatItem(item) }).appendTo($('#playerList'));

Problem is, "playerList" doesn't seem to exist, I see you have a "players" instead?

<ul id="players" />

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

calling a web service in cordova in Visual studio 2015

From Dev

Visual Studio 2015 Method Info

From Dev

How to add a web service reference in Visual Studio 2015 to a console app

From Dev

How do I stop visual studio 2015 for web iis service

From Dev

How to run web service from Microsoft Visual Studio Community 2015

From Dev

Display HTML page using Websharper without Visual Studio

From Dev

Webcam using Visual Studio 2015

From Dev

Create a asmx web service in C# using visual studio 2013

From Dev

Run Web Service using IIS Express without Visual Studio

From Dev

Create a asmx web service in C# using visual studio 2013

From Dev

Xamarin and Visual Studio 2015 display Strange window

From Dev

Template .Net Core Not Display Visual Studio 2015

From Dev

Creating and consuming a web service to call a method with Visual Studio 2015 and c#

From Dev

UWP (Universal Windows Platform) Web Service in Visual Studio 2015 C#

From Dev

Creating and consuming a web service to call a method with Visual Studio 2015 and c#

From Dev

Page Inspector in Visual Studio 2015 RC

From Dev

Page Inspector in Visual Studio 2015 RC

From Dev

Calling restfull service using jquery

From Dev

Web Publishing Extension not installed in Visual Studio 2015

From Dev

where is Web Site Administration on visual studio 2015

From Dev

Web projects missing in Visual Studio 2015

From Dev

Setup a web project with elm in visual studio 2015

From Dev

synchronization between branches in visual studio 2015 and in web

From Dev

JAVA: Restfull web service not passing parameter correctly

From Dev

JAVA: Restfull web service not passing parameter correctly

From Dev

Using Cinder-OpenCV with Visual Studio 2015

From Dev

TeamCity publish using Visual Studio 2015

From Dev

Using Parameters in Visual Studio 2015 Reporting Services

From Dev

Using gulp externally from Visual Studio 2015

Related Related

  1. 1

    calling a web service in cordova in Visual studio 2015

  2. 2

    Visual Studio 2015 Method Info

  3. 3

    How to add a web service reference in Visual Studio 2015 to a console app

  4. 4

    How do I stop visual studio 2015 for web iis service

  5. 5

    How to run web service from Microsoft Visual Studio Community 2015

  6. 6

    Display HTML page using Websharper without Visual Studio

  7. 7

    Webcam using Visual Studio 2015

  8. 8

    Create a asmx web service in C# using visual studio 2013

  9. 9

    Run Web Service using IIS Express without Visual Studio

  10. 10

    Create a asmx web service in C# using visual studio 2013

  11. 11

    Xamarin and Visual Studio 2015 display Strange window

  12. 12

    Template .Net Core Not Display Visual Studio 2015

  13. 13

    Creating and consuming a web service to call a method with Visual Studio 2015 and c#

  14. 14

    UWP (Universal Windows Platform) Web Service in Visual Studio 2015 C#

  15. 15

    Creating and consuming a web service to call a method with Visual Studio 2015 and c#

  16. 16

    Page Inspector in Visual Studio 2015 RC

  17. 17

    Page Inspector in Visual Studio 2015 RC

  18. 18

    Calling restfull service using jquery

  19. 19

    Web Publishing Extension not installed in Visual Studio 2015

  20. 20

    where is Web Site Administration on visual studio 2015

  21. 21

    Web projects missing in Visual Studio 2015

  22. 22

    Setup a web project with elm in visual studio 2015

  23. 23

    synchronization between branches in visual studio 2015 and in web

  24. 24

    JAVA: Restfull web service not passing parameter correctly

  25. 25

    JAVA: Restfull web service not passing parameter correctly

  26. 26

    Using Cinder-OpenCV with Visual Studio 2015

  27. 27

    TeamCity publish using Visual Studio 2015

  28. 28

    Using Parameters in Visual Studio 2015 Reporting Services

  29. 29

    Using gulp externally from Visual Studio 2015

HotTag

Archive