Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  134] [ 5]  / answers: 1 / hits: 38367  / 11 Years ago, sun, july 28, 2013, 12:00:00

I'm trying to create a JS app with the following functionality: A button that gets a JSON document and displays that text. I'm going through an Elasticsearch tutorial, and there is indeed valid JSON at the url I provide:



{_index:planet,_type:hacker,_id:xfSJlRT7RtWwdQDPwkIMWg,_version:1,exists:true, _source : {handle:mark,hobbies:[rollerblading,hacking,coding]}}


When using the code below...I get an alert of



[object Object]


instead of an alert with the full JSON. I'm planning to take the steps next of actually selecting part of the JSON, but I'd like to at least see the full document first...



Any ideas? Thank you in advance!



<!DOCTYPE html>
<html lang=en>
<head><title>Demo</title> <meta http-equiv=content-type content=text/html; charset=utf-8 /></head>

<body>
<input id=testbutton type=button value=Test />
<p id=results>results appended here: </p>

<script type=text/javascript src=jquery-1.10.2.min.js></script>
<script type=text/javascript>
$(document).ready(function() {
$(#testbutton).click(function() {
$.ajax({
url: 'http://localhost:9200/planet/hacker/xfSJlRT7RtWwdQDPwkIMWg',
dataType: 'json',
success: function(data) {
$(#results).append('all good');
alert(data);
},
error: function() {
$(#results).append(error);
alert('error');
}
});
});
});
</script>
</body>
</html>

More From » jquery

 Answers
0

Use alert(JSON.stringify(data));


[#76686] Friday, July 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zackeryzainv

Total Points: 61
Total Questions: 102
Total Answers: 99

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;