Hello everyone,I have made one Rest service in WCF (demo) , which gives me output as : {"GetEmployeeJSONResult":{"Id":101,"Name":"Sumanth","Salary":5000}}Now i have created one website in asp.net in which i am calling this rest service through AJAX JSON...my code is as below:<script type="text/javascript"> $(document).ready(function () { // $.getJSON("http://localhost/SampleService/Service1.svc/getJson?callback=?", null, function (data) { // alert(data.Name); // }); var endpointAddress = "http://localhost/SampleService/Service1.svc"; var url = endpointAddress + "/GetJson"; $.ajax({ type: 'GET', url: url, dataType: 'jsonp', contentType: 'application/json', data: "{}", success: function (result) { //alert(JSON.stringify(result)); alert(result.length); }, error:function(jqXHR) { alert(jqXHR.status); } }); }); </script>You could see that i have accessed service through both AJAX and getJSON methods..now when i am making a alert of data , it shows me output as undefined..i have tried :alert(result.d.length) , alert(result.d.GetEmployeeJSONResult)... but always shows me as undefined..in both methods..Please help me out how to handle this..Thanking you in advance.Krunal 解决方案 这篇关于通过Ajax JSON调用WCF Rest服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-29 10:50
查看更多