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
Sanjay gautam
NA
90
14.4k
web api on ajax call
Sep 29 2019 8:59 AM
I have some code it genrate request and hit api controller but did not return response and hit ajax succes or errror function please suggest me where am i wrong
<
script
type
=
"text/javascript"
>
$(document).ready(function () {
var
ann
= { Name: 'Sanjay', Address: 'Kanpur' };
var
bob
= { Name: 'Jitendra Mehlavat', Address: 'Delhi' };
var
list
= [ann, bob];
var
myjson
=
JSON
.stringify(list);
$('#btn').on('click', function () {
$.ajax({
url: '/api/employee/',
data: myjson,
dataType: 'json',
contentType: 'application/json;
charset
=
utf
-8',
type: "POST",
Succes: function (response,data) {
//alert('success');
var
resdata
=
JSON
.parse(response.d);
alert(resdata);
},
Error: function (response) {
alert('fail');
},
});
});
});
</
script
>
public
class
employeeController : ApiController
{
[HttpPost]
public
string
Post(List<dataarr1> list)
{
return
JsonConvert.SerializeObject(list);
}
model
class
public
class
dataarr1
{
public
string
Name {
get
;
set
; }
public
string
Address {
get
;
set
; }
}
public
class
RootObject
{
public
List<dataarr1> list {
get
;
set
; }
}
public
static
void
Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name:
"DefaultApi"
,
routeTemplate:
"api/{controller}/{id}"
,
defaults:
new
{ id = RouteParameter.Optional }
);
}
Reply
Answers (
4
)
what is % in C#
Time must be egual to data system