I have this ajax code right here:
<script>
$('a[data-id]').click(function () {
var id = $(this).attr('data-id');
var domain = $(this).attr('data-domain');
$.ajax({
url: 'getdata',
type: 'GET',
dataType: 'json',
data: {id: id, domain: domain},
success: function (data) {
var domains = data.name + data.tld;
var tld = data.tld;
$('.resultdomain').html(domains);
}
});
});
</script>
This code works but my problem is that I want to set the tld variable globally to use them in an if statement.
I want to use the variable like this in my code:
if(tld == .de)
{
document.write('<img src="imagelink.png" alt="denic" class="pull-right">')
}
elseif(tld == .com)
{
document.write('<img src="otherimagelink.png" alt="core" class="pull-right">')
}
but I couldn't figure out how I can set the tld variable globally to use it everywhere in my code.
Thanks for any help!