Reputation: 83
I tried making a simple call using JQuery from a web service. It gives me "500 Internal Server Error". Here is my script:
<script type="text/javascript">
$(document).ready(function() {
$("#sayHelloButton").click(function(event) {
$.ajax({
type: "POST",
url: "dummyWebsevice.asmx/HelloToYou",
data: "{'name': '" + $('#name').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
and here is my code at the web service side:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class dummyWebservice : System.Web.Services.WebService
{
[WebMethod()]
public string HelloToYou(string name)
{
return "Hello and welcome, " + name;
}
[WebMethod()]
public string sayHello()
{
return "Hi!";
}
}
I am sorry if my question is redundant, but I can't seem to find my mistake and I am still very new to this. Thank you in advance.
I am following the example from this page: http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx
Upvotes: 2
Views: 7106
Reputation: 28652
I tried your code,and it's working fine.It's look like you have rename the service name in Visual studio. Please check that your are pointing to correct claas
<%@ WebService Language="C#"
CodeBehind="~/App_Code/WebService.cs" Class="dummyWebservice" %>
Upvotes: 3
Reputation: 18344
You should send your data as this:
data: {'name': $('#name').val() },
Hope this helps. Cheers
Upvotes: 1