I have the following code where I am trying to add anchor tag in the HTML as show below :
$.ajax({
url: 'http://localhost:8080/MyAPI/getLinks',
type: 'GET',
dataType: 'json',
success: function(data) {
var jsonObj = JSON.parse(JSON.stringify(data));
$.each(jsonObj.linksList, function(key, value) {
$(".dropdown-content").append('<a href=' + value.webLink + '>' + value.linkText + '</a>');
});
},
error: function(request, error) {
console.log("Inside Error Function ; Request: " + JSON.stringify(request));
}
});
<div class="dropdown">
<button class="dropbtn">Links</button>
<div class="dropdown-content"></div>
</div>
And here’s the JSON that I am using :
{
"webservice_status": {
"status": "SUCCESS",
"message": ""
},
"linksList": [{
"linkText": "Example 1",
"toolTip": "Example 1",
"webLink": "http:/example1.com/home",
"orderList": 30
}, {
"linkText": "Example 2",
"toolTip": "Example 2",
"webLink": "https://example2.com",
"orderList": 40
}, {
"linkText": "Example 3",
"toolTip": "Example 3",
"webLink": "https://example3.com",
"orderList": 50
}, {
"linkText": "Example 4",
"toolTip": "Example 4",
"webLink": "https://example4.com",
"orderList": 52
}]
}
Everything is getting added properly, except the last one as shown below :
<div class="dropdown">
<button class="dropbtn">Quick Links</button>
<div class="dropdown-content">
<a href="http:/example1.com/home">Example 1</a>
<a href="https://www.example2.com">Example 2</a>
<a href="https://www.example3.com">Example 3</a>
<a href="https://example4.com"></a>
"Example 4"
</div>
</div>
I am wondering why the Example 4
is getting added after </a>
tag and not before it just like others?