ajax text 转化 json,JQuery AJAX responseText to JSON

To answer your question directly - you're parsing the json twice - once because you specify dataType: 'json', and again with the $.toJSON. You can probably change the datatype to 'text' and it will solve your problem.

The correct answer though, is to use an asynchronous call with a callback. Someone else has answered the question as I've been typing, so look at their answer instead :)

--edit--

To answer your comments (because formatting doesn't really work in comments). You don't need to stringify the data - you can send it as an object. There's no need to declare the msg variable before the function. Async is the default, so you can just leave that out.

var list = [994, 994, 994, 994];

$.ajax({

type: "POST",

url: "http://www.eaglerider.com/ETS.UI/WebServices/LocationService.asmx/GetMappingLocationDetails",

contentType: "application/json; charset=utf-8",

data: { componentIdCollection: list },

dataType: "json",

sucess: function(msg){

// msg holds your JSON data

console.log(msg);

}

});

Once you've got that msg data, I'm guessing you want to append it to the list, then you would call the function that redraws the location data on the map.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值