function wrong(word){
$("#main-display").html("");
$("#main-display").append("Sorry that is not a valid word");
var word = "lighht";
var check = "https://montanaflynn-spellcheck.p.mashape.com/check/?text=" + word;
// Ajax request to wordsapi
// Will return the synonyms of the searched word
$.ajax({
url: check, // The URL to the API. You can get this in the API page of the API you intend to consume
type: 'GET', // The HTTP Method, can be GET POST PUT DELETE etc
data: {}, // Additional parameters here
dataType: 'json',
success: function(data) { console.dir((data.source)); console.log(data);},
error: function(err) { wrong(word) },
beforeSend: function(xhr) {
console.log(check);
xhr.setRequestHeader("X-Mashape-Authorization", "key"); // Enter here your Mashape key
}
}).done(function(response){
console.log(word);
console.log(response);
var hey = Object.keys(response.corrections);
console.log(hey);
console.log(response.corrections +".lighht");
for (var i = 0; i < 10; i++) {
console.log(Object.keys(response.corrections.lighht));
}
}); // End of ajax of synonyms
그래서 사용자가 입력 한 단어에 가능한 기본 단어를 반환하는 함수를 만들려고합니다. 내가 잘 작동하는 API를 찾았지만 화면에 데이터를 가져 오는 데 어려움을 겪고 있습니다. JSON 객체는 다음과 같습니다 :JavaScript를 사용하여 Ajax 요청을하고 있습니다. 객체를 통과하는 데 도움이 필요합니다.
"lighht"의 객체 키는 단어를 기반으로 변경 될 것입니다. 그래서 다음과 같이 변수를 만들려고 할 때 :
{
"original": "lighht",
"suggestion": "light",
"corrections": {
"lighht": [
"light",
"sleight",
"hightail",
"alright",
"Bligh",
"Lhotse",
"Galahad"
]
}
}
console.log(Object.keys(response.corrections.word[i]));
작동하지 않고 중단됩니다.
그래서이 데이터를 가져 오는 방법을 알아야합니다. 그냥 $.each()
을 사용할 수 있도록 jQuery를 사용하는
는'corrections', 하하지 않는 루프 나는 '단어'라는 속성을 가지고있다. –
나는 그것을 알지 만 사용자 선택에있어 변수가되는 것이 필요하다. – heybit