开发者

yql link list to html

I'm using yql to return a list of links from specific webpages. So far so 开发者_Python百科good, it returns all the links that I pretend, however I don't know how to translate that info into my webpage.

Here's what I'm trying to do:

  • YQL returns a list of links in the results
  • I want those links to appear in my webpage, inside a table, inside divs, etc... like if i wrote them there.

I have been trying to find a way to do this but I don't know much of js and json so I'm here trying to achieve some answer from those of you that might know a way.


There are a couple of ways to do this, depending on which approach you want to take.

First, and simplest, is server-side generation. This is what would result, for example, if a user hits a Submit button on a search form to send you his query, your script receives the query and generates the page, then sends that page to the user. In this case, your question is largely trivial. In pseudocode:

ASSIGN the list of results to list L
FOR EACH ITEM r IN L
    PRINT a string containing an HTML template, substituting the value 
          r where appropriate

It's trivial enough that I suspect you want to do this via DOM manipulation. This is what requires JavaScript: you get the query, send the request without refreshing the page, and want to add the results to the DOM. If you're receiving the list of results, you're already most of the way there. Using jQuery, you would do the same thing as in the pseudocode above, except that where it has the PRINT statement you would have:

$(".SearchResults").append("<li>" + r + "</li>");

I highly recommend reading through the jQuery tutorial. It's not as hard as you think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜