35.1 C
New York
Tuesday, August 9, 2022

How to parse json in jquery ajax?

- Advertisement -





When you are working php or .net etc and you return data like json_encode($data) on ajax request. but in front side you get like a string at that time you have to parse json object and get them. so, let’s see example and learn how to use:

Example

var request = $.ajax({

type: 'POST',

dataType: 'json',

url: 'http://www.mysite.com/getpostuser',

data: {token:obj['token'],postid: obj['postid']}

});

request.done(function(msg) {

msg = JSON.parse(msg);

msg.forEach(function(items) {

var e = "notify-"+items.userid;

io.sockets.emit(e, 1);

});

});

- Advertisement -

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles