I asked a question before on how to add show/hide function to a div and render it exactly when a link is clicked. (The original question) I received an answer to use jquery and ajax together to do this. Here is the code I received:
function unhide(){
$('#id-of-showhide-div').css({'display','block'});
$.ajax({
url: 'http://api.microsofttranslator.com..', // your url to microsoft translator
success: function(data) {
$('#id-of-showhide-div').html(data);
}
});
}
Now since I'm new to this I don't know how to use this. This is the html I tried to make but it doesn't work:
<script type="text/javascript">
function unhide(){
$('#id-of-showhide-div').css({'display','block'});
$.ajax({
url: 'api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=SOMETHING&from=en&to=de&text=Hello', // your url to microsoft translator
success: function(data) {
$('#id-of-showhide-div').html(data);
}
});
}
</script>
<a href="javascript:unhide('a');">Show/Hide Value</a>
<div id="a">javascript:unhide('a');</div>
I the microsofttranslator link outputs some text. I want it to only load that url when someone clicks the Show/Hide value link. And it has to be loaded only once. I mean when someone clicks it, it is rendered and shown, when he clicks it again it gets hidden and when he clicks it once more it doesn't render it once more and shows it from the the first time he clicked it. By the way I have many divs on the page so every id needs to be unique.
Sorry for the long question.
Thanks
PS: If the api is done on the client's side it won't be a problem too.