简体   繁体   中英

Using Jquery to call an ASMX service in sharepoint 2010

The service I'm trying to call is deployed as part of a visual web part. If i call it directly: _layouts/service.asmx I get the expected service page, showing me the functions I want to call. When I do the Jquery Ajax call (it works just fine on my development server) I get a 500 error back from the server.

$.ajax({
    url: 'http://myserver/_layouts/service.asmx/GetLinksToAllFav',
    data: "{'tag': '" + $('#MyTag').val() + "', 'TagMaxLength': '" + $('#TagMaxLength').val() + "'}",
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        $('#MyFav').html(data.d);
        $('#MyFav').show(100);
    },
    error: function (all, textStatus, errorThrown) { console.log(textStatus); console.log(errorThrown); }
});

Response HTTP/1.1 500 Internal Server Error

To get this to work I had to add the following to the web.config file.

  <system.web>
    <webServices>
      <protocols>
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
    </webServices>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM