Reputation: 36048
I have the following we service:
[WebService(Namespace = "http://tono.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
I am able to call the HelloWorld method from html by doing:
<form action="http://localhost:10144/Services/WebService1.asmx/HelloWorld" method="POST">
<input type="submit" value="Invoke" class="button">
</form>
Why am I not able to call it using ajax? why does the javascript code bellow fails?
<script type="text/javascript">
function CallService() {
$.ajax({
type: "POST",
utl: "http://localhost:10144/Services/WebService1.asmx/HelloWorld",
//data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
debugger;
var test1 = response.d;
var test2 = response.data;
},
error: function (er) {
debugger;
}
});
}
</script>
Upvotes: 0
Views: 596
Reputation: 2734
As stated above your utl should be url.
Also in your error function
error: function (er) {
debugger;
}
Change that to the following so the error would be shown to you and you can debug better.
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
Upvotes: 1