I'm new to AJAX
and javascript
. In my project, I have to get a json
object in my javascript
file. I've used spray-json
and it shows me the json object in the url. http://localhost:8081/all-modules
{
"status": "S1000",
"description": "Success",
"results": ["module1", "module2", "module3"]
}
My Ajax call
$.ajax({
url: 'http://localhost:8081/all-modules',
dataType: 'application/json',
complete: function(data){
alert(data)
},
success: function(data){
alert(data)
}
It returns an alert [object Object]
. What is the issue in here?
just console.log(data) you will see your object.
you can access your value by something like this
it also depend on you json how you are creating check this out for explanation
so your code will be like this
try console.log() it will log on the console. alert doesnot displays the object.
Try the following;
You can also check out this link: How to access JSON object in JavaScript
i think you just printing the object.Try someting like this
If you wish to see all the data in the JSON object, use
JSON.stringify
Refer here for more detailsHope that helps.
Try
data[0].status;
. Your data are in an object now. Atconsole.log(data)
you can see that