Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
I have written a wcf service and Iam calling that from javascript.But I couldnt view any response
My code is ..
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript"                   src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">

function invokeService() {
$(document).ready(function(){
$.ajax({
type:"GET",
async:false,
url:"http://localhost:8732/IServices/RoleService/json/name/doctor",
contentType:"application/json; charset=utf-8",
dataType:"json",
processData:true,
success:function(result){
AjaxSucceeded(result);
},
eror:AjaxFailed
});
function AjaxSucceeded(result)
{
alert(result);
}
function AjaxFailed(result){
alert(result.status+''+result.statusText);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="javascript:invokeService();" value="Call WCF Service" />
</div>
</form>
</body>

How can I resolve it?Im getting neither errors nor response ?Where I am going wrong?
Thanks...
Posted
Updated 26-Aug-12 23:38pm
v2
Comments
pramod.hegde 27-Aug-12 6:38am    
Calling WCF comes later.
First check, this javascript function is getting called or not.
Couple of points:
1. Syntax Fix:
Option 1. $(document).ready(function(){...} should be loaded when the form/body of the page loads. Not at the point when you click on any button. The syntax does not look proper here. Fix this first.
Option 2. Completely remove $(document).ready(function(){ line. This is no longer needed.
Option1 needs slightly more modification than Option2. So better you fix the syntax using Option2.
2. WCF Service/Binding:
To call WCF Service, check the type of the service. It should be AjaxEnabledWCF service. Also check the binding. It should be webHttpBinding.
3. Service Return type:
You are expecting the response as 'json'. Check the service response type. It should be 'JSon'.
cutie1 27-Aug-12 7:14am    
$(document).ready(function(){...} .This function is not getting loaded .Can u please tell me where should I modify ?binding is webhttp and it is perfectly returning response in JSON format.So can u please suggenst me where Am I going wrong..How can I verify whether it is AjaxEnabledWCF?What are the modifications I have to do in the above code ?
Thanks,
cutie1 27-Aug-12 7:43am    
Should I attach any jquery library in the project?

1 solution

 
Share this answer
 
Comments
cutie1 27-Aug-12 6:09am    
In the link u gave can u please tell me where I have to write that script tag..In the web.config file?
Prabhakaran Soundarapandian 27-Aug-12 6:13am    
you have to write the <system.servicemodel>.. in web.config file.The <script> tag should be in your asp page only.
cutie1 27-Aug-12 7:16am    
Eventhough I couldn't view response

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900