开发者

JSON response from Ajax service

can any one help me on the query below. I am making an ajax web service call from java script, the web method returns the custom objet, serialization of the object into JSON format is taken care by the Ajax architecture and am not doing any explicit serialization. most of the times I get response properly as below, this gets deserialized and assigned to the variable in my ajax call back function and this works fine. assuming the variable that holds the response as "result", I can access the the data as result._type, result.Action.

{"__type":"Thomson.Financial.RTThomlets.Ajax.State.AjaxCallResult","Action":"Initialize"} 开发者_高级运维

If I close all the browsers and clear the cache and reopen the application the same method returns the response as below

{"d":{"__type":"Thomson.Financial.ThinQuotes.Ajax.State.AjaxCallResult","Action":"Initialize"}}

additional object d is being created automatically, as a result d is assigned to the variable in callback, so when I try to access data as result._type, I get error as this is now under d object.

can any one explain whats going wrong here.

Regards Chandra.


The "d" is being added automatically by the framework to handle a XSS vulnerability. Here is a link that can explain it for you, http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/.


Usually in your callback (are you using jQuery) the first line would be something like:

function successCallback(result){
   result = result.d;
   //and now you're good to go
}

That should help you work with it, but yeah, the actual answer to your question was given above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜