Calling a simple web service (.asmx file) from AJAX and JQuery using JSON-parse error

The first steps in trying to use all these technologies together. I have some problems.
Here is my server side:

[WebMethod (EnableSession = true)]
[ScriptMethod (ResponseFormat = ResponseFormat.Json)]
public string simplestMethod ()
{
  return "Simplest method returned";
}

And here is my client side:

 $ (document) .ready (function () {
   $ ("a"). click (function (event) {     
      $ .ajax ({
      type: "POST",
      url: "http: // localhost: 53346 / d2 / TAPI.asmx / simplestMethod",
      data: "{}",
      contentType: "application / json; charset = utf-8",
      dataType: "json",
      success: function (data) {
       alert (data.d);
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
       alert ("Error Occured!" + "|" + XMLHttpRequest + "|" + textStatus + "|" + 
       errorThrown);
      }
   });
  });
 });

As a result, a warning appears that says:
An error has occurred! | [XMLHttpRequest object] | parseerror | undefined.
What parsing failed and why?
I should mention that calling the WS method directly works.
Many thanks!

+3
source share
2 answers

: url. url "TAPI.asmx/simplestMethod" "/d2/TAPI.asmx/simplestMethod".

, , - -, JSON AJAX WebService? - asmx, json, javascript/jquery?, JSON .asmx Web , ContentType JSON?. - . xhr vb.net, ajax .

+4

WebMethod jquery, web.config

<configuration>
  <system.web>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
  </system.web>
</configuration>

+1

Source: https://habr.com/ru/post/1763423/


All Articles