How to parse json in jquery ajax?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i would like to share with you How to parse json in jquery ajax. When we are working on php or .net etc and we are return data like json_encode($data) on the ajax request. But in the front side we get as like as a string on that time we need to parse json object and we can get them.

so, let’s see the example and then we can 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);
  });
});

Read Also: How to Get Query Strings Value in Laravel?

Thanks for read. I hope it help you. For more you can follow us onĀ facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →