skip to Main Content

This is the result of my API request:

// API callback
showAuth({
    "version": "1.0",
    "encoding": "UTF-8",
    "entry": {
        "content": {
            "type": "html",
            "$t": "u003Cdiv id="data" class="democlass" data-author="Mr. Jhon Doe" data-cat="Technology" data-url="http://www.qbtemplates.com/"u003Eu003C/divu003E u003Cimg alt="Treasury : Minimal Responsive News u0026 Magazine Blogger Template" src="https://4.bp.blogspot.com/-Kv_-Jg5krkA/V8PFfwe1ikI/AAAAAAAAAU0/4J4Dlc0lOJIW2Qbe45TDTMVo4_Ij8MQhACLcB/s1600/Treasury---http___treasury-soratemplates.blogspot.co.jpg" title="Treasury : Minimal Responsive News u0026 Magazine Blogger Template" /u003Eu003Cbr /u003E u003C!-- u003Cul class="item-cta"u003E    u003Cli class="demo"u003E        u003Ca data-demo="true" href="http://treasury-soratemplates.blogspot.com/" rel="nofollow" target="_blank"u003EPreviewu003C/au003E    u003C/liu003E    u003Cli class="download"u003E        u003Ca data-download="true" href="http://qbtemplates.16mb.com/files/Treasury%20Free%20Version.zip" rel="nofollow" target="_blank"u003EDownloadu003C/au003E    u003C/liu003Eu003C/ulu003E--u003E u003Cbr /u003Eu003Cdiv style="text-align: justify;"u003ETreasury is all purpose Blogging blogger theme which can be used for all your blogs like travel, food, life, programming, everyday, fashion and everything you want to blog about. On top of this, great and friendly support makes your website setup experience completely smooth! Treasury Magazine design is excellent for a news, newspaper, magazine, article and editorial publishing or review and rating site. It uses the best clean SEO practices, and on top of that, it’s fast, simple, and easy to use. u003C/divu003E"
        },
        "author": [{
            "name": {
                "$t": "Mikey"
            },
            "uri": {
                "$t": "http://www.blogger.com/profile/05775556662956xxxxxx"
            },
            "email": {
                "$t": "[email protected]"
            },
            "gd$image": {
                "rel": "http://schemas.google.com/g/2005#thumbnail",
                "width": "16",
                "height": "16",
                "src": "http://img1.blogblog.com/img/b16-rounded.gif"
            }
        }],
    }
});

I just trying to extract some data into variable

function showAuth(user) {
    var b = user.entry.author[0];
    c = b.name.$t;
    d = b.gd$image.src.replace(//s[0-9]+(-*c*)//, '/s60$1/');
    e = user.entry.content.$t[0];
    f = e.data - author;
    document.write('<img class="auvtar" alt="' + c + '" src="' + d + '" title="' + c + '"/>' + f + '')
}

The variable c and d result the correct data, but the variable f result no data ( I mean the entire code isn’t functioning if I enable the variable f).

I want to extract the data-cat, data-author, and data-url from entry.content into separated variables, like f, g, and h.

2

Answers


  1. e.data is undefined.

    You are setting e to user.entry.content.$t[0]

    This means that e is the first character in $t which appears to be the long string starting with: "u003Cdiv id="data" class="d

    Login or Signup to reply.
  2. First, remove the [0] in

    • e = user.entry.content.$t[0];

    then convert it to an html element;

    • g = $(e)[0]; // index 0 is the div, you could replace this if you
      want to find a specific element

    and finally you can use it as jQuery object and extract the data values:

    • h = $(g).data(‘author’)

    • i = $(g).data(‘cat’)

    • j = $(g).data(‘url’)

    Cheers!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search