Call MVC4 web API from a regular HTML file outside the project

I am trying to learn the MVC4 web API. I am starting my project from VS2010.

My project url is localhost: 31735

When calling WebAPI directly from the browser itself. It works as localhost: 31735 / api / products /

Now I want to call Webapi from a regular HTML file outside the project.

I tried to do it

 $(document).ready(function () {
           // Send an AJAX request 
            $.getJSON("http://localhost:31735/api/products/",
            function (data) {
            // On success, 'data' contains a list of products. 
               $.each(data, function (key, val) {

                // Format the text to display. 
                var str = val.Name + ': $' + val.Price;

                // Add a list item for the product. 
                $('<li/>', { html: str }).appendTo($('#products'));
            });
        });
    });

But that does not work. You can help.

+1
source share
1 answer

Now I want to call Webapi from a regular HTML file outside the project.

- , AJAX . , JSONP JSON.

, , , .

+3

Source: https://habr.com/ru/post/1609191/


All Articles