Web API Using JQuery AJAX In ASP.NET MVC 5 getting error "Invalid or unexpected token"
I have created a Web Api project with MVC. Which contains HomeController having Action method index
- public ActionResult Index()
- {
- return View();
- }
For above action method I would like to show employee details from ajax call in javascript alert message as
- @{
- Layout = null;
- }
- <script src="~/Script/jquery-1.10.2.min.js">script>
- >
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>Indextitle>
- head>
- <body>
- <div><h2>You Are On Viewh2>div>
- body>
- html>
- <script>
-
- $(document).ready(function () {
- $.ajax({
- type: 'GET',
- url: "http://localhost:802/api/Employee/GetEmployee?Id=101",
- contentType: "application/json; charset=utf-8",
- dataType: "jsonp",
- success: function (data) {
- alert(data);
-
- },
- failure: function (data) {
- alert("Failure: "+ data);
- },
- error: function (data) {
- alert("Error: "+ data);
- }
- });
Also I have created one api controller as follows, which will return employee details
- public class EmployeeController : ApiController
- {
- public Employee GetEmployee(int Id)
- {
- Employee objEmp = new Employee();
- objEmp = ;
- return objEmp;
- }
- }
I tried below solution
http://www.c-sharpcorner.com/article/call-web-api-using-jquery-ajax-in-asp-net-core/
I am getting error like "Uncaught SyntaxError: Invalid or unexpected token" in console.
If I click on the error in console then I am getting my result as
{ "EmpId": "101","Name": "Rupesh" }