Hi I’m trying to access a WCF service which returns a JSON Array using JQuery but its not working. But when I use a php service which is in internet it works.
please tell me where i’m going wrong?
My c# class
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(Method = "GET",RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
Employee[] getData();
}
[DataContract]
public class Employee
{
[DataMember]
public string id { get; set; }
[DataMember]
public string name { get; set; }
}
The response i get when i load it in browser
[{"id":"1","name":"test"},{"id":"2","name":"test"}]
the URL for php web service
http://shell.loopj.com/tokeninput/tvshows.php
my html code
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: "http://localhost:51220/Service1.svc/getdata",
success: function(result){
alert(result);
},
dataType: "jsonp"
});
});
</script>
when i use this i get the error 0 but when i use the php service i get the array.
Try the following code.