I tried several combinations of this source, but i'm new to jQuery and I can't find a basic tutorial which I can understand.
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
</head>
<body>
<script>
var sourceText = "car";
var transText = "";
$.getJSON("http://www.worldlingo.com/S000.1/api?wl_password=secret&wl_srclang=EN&wl_trglang=IT&wl_text=" + sourceText,
function(data){
alert("Data: " + data);
}).error(function(jqXHR, textStatus, errorThrown){
console.log("ERR: %o" , jqXHR);
console.log("Result: %s" , jqXHR.responseText);
transText=jqXHR.responseText;
alert("Translation JSON data provided for '" + sourceText + "': '" + transText + "'");
})
</script>
</body>
</html>
I want just to get the translation of a word.
Why do I get the translation as an error rather than as a result?
Why does the execution never get to alert(data) if the data are actually successfully received?
Edit: final answer is: server is NOT providing a JSON response, hence the source above is working correctly, triggering an error due to wrong MIME type received.
XMLHttpRequest cannot load http://www.worldlingo.com/S000.1/api?wl_password=secret&wl_srclang=EN&wl_trglang=IT&wl_text=car. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '....' is therefore not allowed access.