i have some code it produced incorrect url where am i wrong please suggest me
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using System.Web.Services;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
-
- namespace jsonserialize
- {
- public class EmployeeAPIController : ApiController
- {
- [WebMethod]
- public static string SerializeDeserialize(string data)
- {
- DataTable dt = new DataTable();
-
- JArray arrays = (JArray)JsonConvert.DeserializeObject(data);
- if (arrays.Count > 0)
- {
- foreach (JToken jToken in arrays[0])
- {
- dt.Columns.Add((jToken as JValue).Value.ToString());
- }
- int i = 0;
- foreach (var array in arrays)
- {
- if (i > 0)
- {
- DataRow dr = dt.NewRow();
- int j = 0;
- foreach (JToken jToken in array)
- {
- dr[j] = (jToken as JValue).Value;
- j++;
- }
- dt.Rows.Add(dr);
- }
- i++;
- }
- }
-
- return JsonConvert.SerializeObject(dt);
- }
- }
- }
- >
- <html>
- <head>
- <meta charset="utf-8" />
- <title>title>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">script>
- <script type="text/javascript">
- $(document).ready(function () {
- $('#btn').on('click', function () {
- var arr =
- [
- ["EmployeeId", "Company", "EmployeeName", "Location"],
- [211, "inyxa", "Sanjay", "Faridabad"],
- [235, "Tata", "Shashank mishra", "Noida"],
- [123, "Kabir infosystem", "Surya singh", "Gaziabad"],
- [444, "Velocis", "Ajay kumar", "Merath"],
- [595, "W3wila", "Virendra shakya", "Kanpur"],
- [256, "Tech Mahindra", "Ayush trivedi", "Banaras"]
- ];
- var myjson = JSON.stringify(arr);
- $.ajax({
- type: 'POST',
- url: "../api/EmployeeAPI",
- data: "{'data':'" + myjson + "'}",
- dataType: 'json',
- contentType: "application/json; charset=utf-8",
- success: function (response){
- var employees = JSON.parse(response.d);
- },
- error: function (response) {
- alert(response.d);
- }
- });
- });
- });
- script>
- head>
- <body>
- <input id="btn" type="button" value="Serialize Deserialize" />
- <hr />
- <table id="tbl">
- <tr>
- <th>Idth>
- <th>Nameth>
- <th>Companyth>
- <th>Locationth>
- tr>
- <tr>
- <td>td>
- <td>td>
- <td>td>
- <td>td>
- tr>
- table>
- body>
- html>
Jaimin ShethiyaPosted Sep 30, 2019, 7:47 AM
are you write the url is wrong, can you please changes it to given as below and after checked it worked or not.
url: "/api/EmployeeAPI",
let me know if you have needed any other help from myside.
Thanks
Sanjay gautamPosted Sep 28, 2019, 4:52 AM
Dinesh GabhanePosted Sep 28, 2019, 4:01 AM