Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Calling a Web Service From HTML File With JQuery AJAX

$
0
0

Hi all, I have a web service that has a simple web method that takes two parameters of type interger and it returns the result of adding the two numbers together. I made sure to uncomment the following line in my code behind:

[System.Web.Script.Services.ScriptService()]

I am trying to call this webservice from a regular html file using jquery ajax using the following code:

$.ajax({
   type: "POST",
   url: "../MyService.asmx/AddNumbers",
   data: "{'a':" + $('#txtData1').val()+ 'b': + $('#txtData2').val()+ "}",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function (response, status){
   //alert(response.d);
   $('#output').empty();
   $('#output').append(response.d);},
   failure: function (){
   alert("Failed!");
   }
 });

When I try to call the webservice from my html file I get the "Failed!" alert message. I don't know what else I have to include aside from what I aready have.

Please help me resolve this problem, thanks in advance.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>