How to insert value of Json variable into a href attribute? [duplicate]

-1

A question I wanted to put a variable inside the link href without using code, that is direct in the creation of the link.

The example is just below:

<a href="http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_COD_UNI=" + [CODIGO_RASTREAMENTO] targert="_blank">código de rastreamento</a>

The variable [CODIGO_RASTREAMENTO] comes from a Json file that is on the server side.

Note: I can not use scripts .

    
asked by anonymous 08.05.2014 / 14:20

1 answer

1

You need to parse the json string to make it an object variable.

//JQuery
var objJson = $.parseJSON("string json");

//Javascript
var objJson = JSON.parse("string json");

So you could use the objJson object variable and call its attributes.

jQuery example of how to put href

$("#seu-link").attr("href",objJson.CODIGO_RASTREAMENTO);

08.05.2014 / 14:41