问题
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
回答1:
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>
来源:https://stackoverflow.com/questions/9035539/using-jquery-to-call-an-asmx-service-in-sharepoint-2010