title: How to resolve Error: Unexpected token '<' in Asp.Net request?
body: <p>I am trying to call a WebService in my <code>ASP. Net</code> app and am getting the following error: <code>Error:  Unexpected token '&lt;'</code>. So far it seems like a <code>json</code> parsing issue, but I am not sure how to resolve it. In my app, I have a data manager that calls a stored procedure from a local <code>SQL .mdf</code> database. Essentially, its a public <code>DataTable</code> called  GetEventsByState() and it is stored in my <code>DataAcessManager.cs</code> file. It is called from a WebService in my App_Service.asmx.cs file. The goal is to return the <code>datatable</code> as json in the <code>WebService</code> so I can then call it in my <code>app.js</code> file:</p>
  
  <p>RII_Service.cs</p>
  
  <pre><code>    [WebMethod]
      public string GetListOfEventsByState()
      {
          _dtMgr = new DataAccessManager();
          //string state = st;
          /*HttpContext.Current.Response.Write(GetEventsData());*/
          DataTable EventsList = _dtMgr.GetEventsByState();
          var lst = EventsList.AsEnumerable()
              .Select(r =&gt; r.Table.Columns.Cast&lt;DataColumn&gt;()
                  .Select(c =&gt; new KeyValuePair&lt;string, object&gt;(c.ColumnName, r[c.Ordinal])
                  ).ToDictionary(z =&gt; z.Key, z =&gt; z.Value)
              ).ToList();
          //now serialize it
          try
          {
              string json = new JavaScriptSerializer().Serialize(lst);
              json = json.TrimEnd();
              return json;
          }
          catch (Exception e)
          {
              throw new Exception(e.Message);
          }
      }
  </code></pre>
  
  <p>This <code>WebMethod</code> is then called in <code>app.js</code> on page load like this:</p>
  
  <p>app.js</p>
  
  <pre><code>//Function to call Asp.Net Web Service and retrieve events list by state
  var EventsData = esriRequest({
      url: "RII_Service.asmx/GetListOfEventsByState",
      content: {
      },
      dataType: "jsonp",
      handleAs: "json"
  });
  EventsData.then(
      function (response) {
          console.log(response);
          events_json = response;
  ....
  }, function (error) {
      console.log("Error: ", error.message);
  }); 
  </code></pre>
  
  <p>When I put break points on RII_Service.cs for the <code>WebMethod</code> GetListOfEventsByState(), it produces a viable json string that looks like this:</p>
  
  <p><code>"[{\"FullEventName\":\"NJ Cindy 2005\",\"State\":\"NJ\"},{\"FullEventName\":\"NJ Gordon 2000\",\"State\":\"NJ\"}...]</code></p>
  
  <p>However when it goes back to the <code>EventsData</code> request, it goes right to the error. Any clues or suggestions as to what I am doing wrong here. </p>