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 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 list { get; set; }
- }
- public static void Register(HttpConfiguration config)
- {
-
-
-
- config.MapHttpAttributeRoutes();
-
- config.Routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new { id = RouteParameter.Optional }
- );
- }
Jaimin ShethiyaPosted Sep 30, 2019, 7:39 AM
can you please used below code for and check the working or not.
let me know if you have needed any other help from myside.
Thanks
Amit JPosted Oct 3, 2019, 1:17 AM
Rajeesh MenothPosted Sep 30, 2019, 12:57 AM
Salman BegPosted Sep 29, 2019, 11:23 PM