私は顔の認識APIからajaxレスポンスを取得しようとしています。応答は、顔のデータの特徴である、 エラーメッセージがあるif文にエラーメッセージを入れる方法if(...)
{"Errors":[{"Message":"no faces found in the image","ErrCode":5002}]}
応答メッセージは、私が「成功」を警告することができるように、私がもし/ else文を書く必要がありますどのように
{"images":[{"status":"Complete","width":236,}]}]}
です顔/応答がある場合は警告を表示し、顔/エラーがない場合は「失敗」を警告しますか?
$("#testDetect").click(function() {
var file = $('#imageFile')[0].files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = function() {
var imageData = parseImageData(reader.result);
var data = {};
data.image = imageData;
$.ajax({
url : "http://localhost/Karios/simple-detect/form-post.php",
type : "POST",
data : data,
dataType : 'text'
}).done(function(response) {
console.log(response);
if (!response) {
alert('Hmm, unexpected response from Kairos');
} else if (response['Errors'] && response['Errors'].size() > 0) {
if (response['Errors'][0]['ErrCode'] == 5002) {
alert(response['Errors'][0]['Message']);
} else {
alert('Some other error occurred:\n' + response['Errors']['ErrorCode'] + ': ' + response['Errors']['Message']);
}
} else {
alert('Face(s) detected');
}
})
}
});
顔や警告がある場合、 "不合格" の顔
エラーが発生していないときにどのような応答が返ってくるのですか? –
あなたはajax呼び出しに渡すオブジェクトを2つ以上渡すことができます。エラーと成功は両方ともコールバックです。何らかのエラーが発生した場合、エラーコールバックは成功コールバックと呼ばれます。この方法では、エラーを処理する場所を正確に知ることができます。 – nurulnabi
@UjjwalKumarGupta彼らが私に応答を送ったら、「成功」を警告したい。彼らが私にエラーを送った場合、私は "失敗"を警告したい。 –