Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

How to communicate between simple htm page and Web API

$
0
0

Hi,

I am having a simple htm page (in a simple web application not in MVC4 application) with the <script> tag holding the following code to call the Web API Controller:

$(function () {
     $.ajax({
             type: "POST",
             url: "api/Sample/1",
             data: null,
             success: null,
             complete: null,
             error: null
       });
});

Now in the controller file when I have the breakpoints marked it shows the following error:

“The breakpoint will not currently be hit. No symbols have been loaded for this document.”

Controller code:

public class Sample : ApiController
{
// GET /api/<controller>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}

// GET /api/<controller>/5
public string Get(int id)
{
return "value";
}

// POST /api/<controller>
public void Post(string value)
{
}

// PUT /api/<controller>/5
public void Put(int id, string value)
{
}

// DELETE /api/<controller>/5
public void Delete(int id)
{
}
}

Now my queries are:

1) Will it be possible to call a method from WebAPI throught the script in html file in a simple web application.

2) If so how? Kinldy provide me the detailed steps as I am new to this.

3) If this is not possible then kindly suggest a way to communicate from the script portion of htm page to any web service so that I can carry on the process there and return my data as JSON.

Thanks in Advance


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>