开发者

javascript ajax response in jquery

I am using jquery to call a legacy system which returns the following response:

<script type="text/javascript">
var responseObj = {
   success: ('0'=='0'),
   cfgInfo: {
        deletedId: ''
   },
   data: {
          id:"9470",devicePIFrom:"10.10.10.34",devicePIFromAlias:"10.10.10.34",
          deviceCommunityRW:"",deviceCommunityRO:"H1ghL!ght",devicePIUseProxy:"1",
          devicePITo:"10.10.10.10",devicePIToAlias:"Fake  local server",
          devicePISrcIP:"6.6.6.6",piStyle:"ICMPPing",SLAdelay:"100",
          devicePIToPort:"0",piWanted:"1",piAutoClasses:"",piNocDisabled:"",
          piCtrlPacketSize:'50',piTestInterval:'0',piProbeInterval:'',piProbeCount:'',
      piMOSCodec:'0',pimosSLA:'3.5',piSLAPacketLoss:'0.05',piSLAJitter:'20'
   },
   errors: [

   ]
}
</script>

My jquery looks like this:

$.ajax({
                    type: "GET",
                    url: requestString,
            dataType: 'scrip开发者_运维知识库t',
                    success: function(data){
                    .....do stuff......
                    }
});

How can I get at the responseObj given that I cannot change the legacy system's response format?


thanks for the help - in the end ext-js gave me the answer:

using var response = eval("(" + data + ')'); to process the response string yields the javascript object - I can then access the properties directly as follows:

$.ajax({
    type: "GET",
    url: requestString,
dataType: 'script',
    success: function(data){
   var response = eval("(" + data + ')');
       if(response.success) {
           ...do stuff.....
       }
    }
});

obscure but it works!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜