www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript JSONP YQL query

  1. #1
    Join Date
    Oct 2011
    Posts
    3

    Javascript JSONP YQL query

    Hi there,

    I have put together some YQL code that works for RSS feeds, but I'm trying to get it to parse some HTML for me. I'm wondering what's wrong here:

    This code works fine:

    Code:
    function buildListOfItems(data) {
    	var items = data.query.results.item;
    	var output = '';
    	if (items && item.length) {
    		var no_items=items.length;
    		for(var i=0;i<no_items;i++){
    			var title = items[i].title;
    			var content = items[i].content;
    			output += title + "-->" + content + "<br/>";	
    		}
    		return output;
    	}else{
    		alert('no data returned!');
    	}
    }
    
    function theCallback(data)   { 
    	$("#menuitems").html(buildListOfItems(data)); 
    }
    
    $.YQL = function(query, callback){  
    	$.ajax({
    			type: "GET",
    			url: 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query.toLowerCase()) + '&format=json&diagnostics=false&callback=?',
    			success: callback,
    			dataType: "jsonp"
    	});
    };
    
    
    $(document).ready(function() {
       $.YQL("select * from feed where url='http://feeds.feedburner.com/t3kd?format=xml' limit 10", theCallback);
    });

    but if I change the YQL line to something like this:

    Code:
    $.YQL('select title,content from html where url="http://www.mywebsite.com/index.php?page=10" and xpath='//h3/a''', theCallback);
    then I get 'no data returned'

    However the query works fine in the YQL console, I wonder am I just not encoding the string right or missing a single quote vs double quote problem?

    If anybody can help me I'd really appreciate it.
    Thanks

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    some APIs require an api key to work outside of the console...

  3. #3
    Join Date
    Oct 2011
    Posts
    3
    yes that was my first thought but is that definitely the case with their 'HTML' table ? There doesn't seem to be a list of what does and doesn't require the key?

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    depends on the site. check it's robots.txt and crossdomain.xml file in the site's root folder.


    also, you may have nested apos as quotes issues in the posted code; i see three apos in a row...

  5. #5
    Join Date
    Oct 2011
    Posts
    3
    Hi there,

    It's a site I developed myself and I'm ashamed to admit (*blush*) - I haven't included either file in the root.

    To be honest, I think I might have to start all over again with this code and learn more because I've now noticed that it's not even working in Google Chrome for the RSS query

    Code:
    $.YQL("select * from feed where url='http://feeds.feedburner.com/t3kd?format=xml' limit 10", theCallback);
    but that still works fine in IE8. (strange).

    any pointers at all would help but I'll probably have to learn some basics again as I must be doing something wrong.

    Thanks again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles