Sims
Sims

Reputation: 177

"Dynamic" jQuery JSON request

Hello everybody and merry Christmas!

$.getJSON("MyURL",null ,function(result){
    $("winp").each(function () {
        var typ = $(this).attr( "type" );
        var val = result.typ;
        alert(val);
    });
});

I have multiple custom HTML tags like <winp type="something"></winp>

I get the value of "type", but when I try to show the result from the JSON request, i get 'undefined'.

Any ideas why the JSON request doesn't return anything?

Upvotes: 1

Views: 53

Answers (1)

Satpal
Satpal

Reputation: 133403

Assuming you want to get result.something, You should use bracket notation

var val = result[typ];

Upvotes: 1

Related Questions