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 ShethiyaRank #177 · 13.7K reputationPosted Sep 30, 2019, 3:39 AM EDT
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
Salman BegRank #284 · 8.8K reputationPosted Sep 29, 2019, 7:23 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Sep 29, 2019, 8:57 PM EDT
Amit J42 reputationPosted Oct 2, 2019, 9:17 PM EDT