Click here to Skip to main content
12,947,379 members (49,883 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 22:27pm
cutie1297
Comments
hitesh_tech 29-Aug-12 11:44am
   
What are you getting in alert(msg); ?
cutie1 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
Top Experts
Last 24hrsThis month
OriginalGriff 5,059
CHill60 3,235
Maciej Los 2,538
Jochen Arndt 1,935
ppolymorphe 1,795


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2017
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