I'm completely new to JSON, JS and AJAX. I'm used some example codes to progress through my targets. What I don't understand is when the JSON is an error object the success section is still firing. The console shows error where object d is null or a non-object when error is true. What have I done incorrectly? TIA
Result type good:
JSON: {"data":["1","breast","2","wing","3","thigh","4","leg","5","half","6","quarter white","7","quarter dark","9","whole"],"error":false}
Result type error:
JSON: {"error":true}
$.ajax({
type : 'GET',
url : 'getsubtypes2.php',
data : dataString,
dataType : 'JSON',
cache: false,
success : function(data) {
var output;
var d = data.data;
var output = "";
for (var i = 0 ; i< d.length; i=i+2) {//error gets to this line
var count = d[i];
var newOption = d[i+1];
output += "<option value='"+count+"'>"+newOption+"</option>";
}
$('#select3').empty().append(output);
},
error: function(){
$('#select3').empty();
console.log("Ajax failed");
}
});