I have to encode a domain name (IDNA) for a particular registrar using accents.
I have a simple input field :
<input type="text" id="idndomain" name="sld[0]" size="40" />
My jQuery function
$(document).ready(function() {
$('#domainform').submit(function(){
$.getJSON("includes/idna/idna.php", {
domain: $("input#idndomain").val()
}, function(data){
$("div#result").html($('<b>' + data.encoded + '</b>'));
$('#idndomain').val(data.encoded);
});
return true;
});
});
So i'm sending a query to idna.php which encodes the domain name and returns a json array :
{"encoded":"xn--caf-dma.ch"}
Problem is that the form is being submited with the 'original' value, not the value returned by the json query.
Question is : how to 'wait' for json result first, replace the input field with the encoded string and them submit ?