Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to display specific parts of a Cloudant database. This database contains many separate documents, and each document contains a category called "results". I'm trying to display whatever is in results. Each document is identified by its own id. I tried using the get() method in jQuery, but unfortunately it is not running successfully.

 function grabData(){
  var url = 'https://cloudant.com/futon/document.html?acharya%2Ftoxtweet/ff558f75077e8c758523cd3bd8ffdf88';
   $.get(url, function(data) {
     $('.result').html(data);
       alert("Data loaded: " + data);
});
}
grabData();

I'm not entirely sure where I went wrong...Should I consider using SQL instead of ajax?

share|improve this question
what do you get as alert ? – Yasser Dec 22 '12 at 5:46
1  
What is the content type you are expecting? default is html. – Murali Dec 22 '12 at 5:49
What type of data is there category called "results"? – Jai Dec 22 '12 at 5:53
I got nothing as alert. It's just a blank page when I run it – Carrie Dec 23 '12 at 1:13

2 Answers

The URL you are using is returning an entire webpage.

Your jQeury code is looking for an element on the current page with a class name of result and trying to change it's inner HTML to the response from the URL.

You didn't provide any additional code to look at, but I would assume that is not what you were expecting it to do.

I assume you are wanting to parse through the entire url, but in your current code the page will be processed as a raw string and not a DOM object. So you would have to parse through that string with regular expressions, etc.

share|improve this answer

I think your issue it this:

replace this:

grabData();

with this:

$(document).ready(function(){
    grabData();
});

or more shortened:

$(function(){
    grabData();
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.