Ajax local success, but no data returned

I created two projects in Visual Studio 2010, one of them is a web service and the other is a web application. I have a method in a web service as follows:

`[OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "json/getData")]
    List<Objects> TestCall();`

Once I started the service, I can happily type the URL to get a JSON response:

http://localhost:17258/RestService.svc/json/getData

leads to

{"TestCallResult":[{"id":1,"name":"Title"}, {"id":2,"name":"Title"},{"id":3,"name":"Title"},{"id":4,"name":"Title"}]}

However, in my web application, when I try to make this Ajax call to get this response, I get success from the call, but the JSON is null, here is my ajax call:

`$.ajax({
                url: "http://localhost:17258/RestService.svc/json/getData",
                type: "GET",
                mimeType: "application/json",
                dataType: "json",
                cache: false,
                success: function (json, status) {
                    alert("Success JSON=" + json + ", status=" + status);
                    var obj = jQuery.parseJSON(json);
                    for (var i = 0; i <= obj.length; i++) {
                        alert(obj[i].id);
                    }
                }
            });`                

I try in FireFox and the json variable returns as null when IE debugger is being debugged, I can add a clock to the object and see that the object has an array under it, I need to use json.TestCallResult or anyone else saw this difference between IE and FireFox OR can someone say stop being a noob and do it ...

thank

+3
4

URL- ajax : , html-url.

0

u json. $.parseJSON, . http://jsfiddle.net/H4v8G/

0

You need to look json.dinstead json.

Response data is included in the property .d, and not directly in the returned object.

This happens with ASP.NET 3.5 and later.

0
source
$.ajax({
                url: "http://localhost:17258/RestService.svc/json/getData",
                type: "GET",
                dataType: "json",
                cache: false,
                success: function (obj) {
                    for (var i = 0; i <= obj.length; i++) {
                        alert(obj[i].id);
        }
     }
});

try it

0
source

All Articles