Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript WCF
Hii,
 
I have made a WCF REST service which returns the response in JSON format and now I want to call it from javascript.But when I try to call it I couldn't view any response.
To make a javascript call I have written this:
<script src="Scripts/jquery-1.5.2.min.js" type="text/javascript">
   </script>
   <script language="javascript" type="text/javascript">
       function Greeting() {
          
           $("#btnWCFREST").click(function() {
           $.ajax({
           url:"http://localhost:8732/Services/RoleService/json/Role/provider",
          
           type:"GET",
           dataType:"json",
         
            contentType:"application/json; charset=utf-8",
            successs:function(msg){
            alert(msg);
            },
            Error:function(msg){
            alert("Failed");
            }
            }
 
            );
            }
            }
 

   </script>
 
How can I get the response.Where Am I going wrong?
 
Thanks..
Posted 28-Aug-12 23:27pm
cutie1297
Comments
hitesh_tech at 29-Aug-12 11:44am
   
What are you getting in alert(msg); ?
cutie1 at 29-Aug-12 12:35pm
   
I even cant view the alert (msg)..I cant view any action on page load when I click the button

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

<script type="text/javascript">
 
var Type;
var Url ="http://..... "// service URL;
var Data;
var ContentType;
var DataType;
var ProcessData;
var method;
//Generic function to call WCF Service
 

function CallService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url, // Location of the service
data: Data, //Data sent to server
contentType: ContentType, // content type sent to server
dataType: DataType, //Expected data format from server
processdata: ProcessData, //True or False
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
 
function ServiceFailed(result) {
Type = null;
Url = null;
Data = null;
ContentType = null;
DataType = null;
ProcessData = null;
}
 

function GetEmployee() {
var uesrid = "1";
Type = "POST";
ContentType = "application/json; charset=utf-8";
Data = "{'Location=Pune'}";
DataType = "jsonp"; ProcessData = false;
method = "sayHello";
CallService();
}
 
function ServiceSucceeded(result) {
if (DataType == "jsonp") {
if (method == "CreateEmployee") {
alert(result);
}
else {
 
alert("Succ 1 - " + result)
var string = result[1].Actionname + " \n " + result[0].Actionname;
alert(string);
}
}
}
}
 
$(document).ready(
function () {
try {
GetEmployee();
} catch (exception) { }
}
);
 

 
</script>
  Permalink  
v2

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 23 Mar 2013
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