locked
Failed to load resource: the server responded with a status of 500 (Internal Server Error) RRS feed

  • Question

  • User998291137 posted

    hi,

    I am trying to follow this tutorial :https://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api , just renamed products to planes 

    This part work ok :   

        var uri = 'api/planes';

    var id = $('#planeId').val();
          $.getJSON(uri + '/' + id)

    But I see a error with the 'Get' 

    status of 500 (Internal Server Error) is seen when the page loads .  Any tips how to debug this ?

    http://localhost:1926/index.html   ,  calls the C# Get method

        public class PlanesController : ApiController
        {
            public IEnumerable<string> Get()
            {
                return new string[] { "value1", "value2" };
            }

            Plane[] planes = new Plane[]
            {etc

    Thanks,Peter

    Saturday, October 8, 2016 7:10 PM

Answers

  • User998291137 posted

    hi Yohann,

    I finally found the error. I had a extra get method in the controller.

    I ran it in Chrome browser, and hit f12 and saw a error about multiple methods.

    Thanks for your help,

    Peter

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 11:38 AM

All replies

  • User36583972 posted

    Hi petercli,

    status of 500 (Internal Server Error) is seen when the page loads .  Any tips how to debug this ?

    Your tutorial is explain more detailed. Please make sure you have a correct url to call Get Method.

    You can use F12 to view the HTTP Request and Response.

    You can also try the following ajax code to call a get method.

        $.ajax({
                        url: "http://182.18.161.151:9010/api/planes",
                        type: "Get",//Post"
                        headers: { "Accept": "application/json; odata=nometadata" },
                        contentType: "application/json; charset=urf-8",
                        dataType: "json",
                        success: function (response) {
                            alert(response)
                        }, 
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert("error-Put:" + textStatus + "  " + errorThrown);
                        }
                    });
    

    Best Regards,

    Yohann Lu

    Monday, October 10, 2016 5:07 AM
  • User998291137 posted

    hi Yohann,

    I finally found the error. I had a extra get method in the controller.

    I ran it in Chrome browser, and hit f12 and saw a error about multiple methods.

    Thanks for your help,

    Peter

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2016 11:38 AM