TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rupesh Kahane
102
19.1k
4.2m
Web API Using JQuery AJAX In ASP.NET MVC 5 getting error
Nov 30 2017 6:46 AM
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
>
Index
title
>
head
>
<
body
>
<
div
>
<
h2
>
You Are On View
h2
>
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 = ;
// get data from service
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" }
Reply
Answers (
2
)
Display currency symbol in c# in pdf
pass radio button value to controller without submit button