Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi All,
 
How to call Webservices through an API using Jquery from an MVC application
 

 
Thanks & Regards,
Soumya
Posted 17-Sep-12 21:17pm
soumyaraj1.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well, its not that much related to MVC, if you want to use JQuery to call your web service you can use the $.ajax method (tons of examples and links on using that), keep in mind that will call the web service from the client side and it has nothing to do whether you are using MVC or ASP.NET forms or whatever it is your web application.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have added Below lines of coding .but it display a messagebox with a message 'undefined'
 

<script type="text/javascript" src="../../Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" language="javascript">
 
        function callservice() {
 
            $.ajax({
 
                type: "POST",
                url: "http://www.webservicex.net/country.asmx?wsdl",
                //        data:'{}',
                contenttype: "application/json;charset=utf-8",
                datatype: "json",
                success: onsuccesscall (response),
                Error: onerrorcall
            });
        }
function onsuccesscall(response)
{
alert(response.d);
    $("#divresponse").text(response.d);
//   alert('hello');
}
 
function onerrorcall() {
    alert('not working');
 
}
    </script>
</head>
<body>
<form id="fm1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button"  OnClientClick="callservice();"/>
    <div id="divresponse">
 
    </div>
    </form>
</body>
</html>
 
------------------------------------------------------------
In HomeController I have added below lines of coding
public ActionResult web_ser_call()
       {
           return View();
 
       }
  Permalink  
Comments
Member 9441893 at 26-Oct-12 7:21am
   
what is response
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here I have solved with the below coding
 

function callservice() {
 

var pageUrl = "../webservices/WebService1.asmx"
 

$.ajax({
type: "POST",
url: pageUrl + "/HelloWorld",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessCall,
error: OnErrorCall
});
 

}
 

function OnSuccessCall(response) {
alert(response.d);
 
}
 

function OnErrorCall(response) {
alert(response.status + " " + response.statusText);
}
 

 
<body>
<form id="fm1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button"  OnClientClick="callservice();"/>
    <div id="divresponse">
 
    </div>
    </form>
</body>
</html
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 555
1 Sergey Alexandrovich Kryukov 305
2 BillWoodruff 259
3 CPallini 220
4 PIEBALDconsult 220
0 Sergey Alexandrovich Kryukov 10,615
1 Maciej Los 5,354
2 OriginalGriff 5,254
3 CPallini 3,719
4 BillWoodruff 3,476


Advertise | Privacy | Mobile
Web01 | 2.8.141029.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100