Do I have to use JSON. parse () when I am accessing data from an api using ajax(jQuery)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Do I have to use JSON. parse () when I am accessing data from an api using ajax(jQuery)?

2nd Jul 2018, 1:07 PM
Jenny
Jenny - avatar
4 Answers
+ 4
I haven't used it here and it's still working. Toni Isotalo can you tell me why is it so? https://code.sololearn.com/WQi9V4ROW7L2/?ref=app
2nd Jul 2018, 1:28 PM
Agnibha Chakraborty
Agnibha Chakraborty - avatar
+ 4
Apparently it depends on the content type of the api. Most API content types are application/json you don't need to parse it. But if there's no content type header set it's a string.
2nd Jul 2018, 1:45 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
JSON.stringify usually works well (depending on the data). here is an example. https://code.sololearn.com/WA6VU5LNNvvt/?ref=app
5th Jul 2018, 2:18 AM
Logan
Logan - avatar
0
you can parse the json in backend and return the data in succes: inside ajax call and there you can play with it. i think this is what you need?
10th Jul 2018, 8:46 PM
Catalin Popinciuc
Catalin Popinciuc - avatar