01.
$.ajax({
02.
url:
"test_exam.php"
,
03.
type:
"POST"
,
04.
dataType:
'json'
,
05.
data: { keyword: $(
'#mtr_id'
+i).val()},
06.
success: (obj)=>{
07.
$(
"#div1"
).empty();
08.
$.each(obj,
function
(key, val) {
09.
$(
"#div1"
).append(
'หน่วย ('
+ val.unit_mrt+
')'
);
10.
});
11.
},
12.
error: (jqXHR, exception)=>{
13.
var
msg =
''
;
14.
if
(jqXHR.status === 0) { msg =
'Not connect.\n Verify Network.'
;
15.
}
else
if
(jqXHR.status === 404) { msg =
'Requested page not found. [404]'
;
16.
}
else
if
(jqXHR.status === 500) { msg =
'Internal Server Error [500].'
;
17.
}
else
if
(exception ===
'parsererror'
) { msg =
'Requested JSON parse failed.'
;
18.
}
else
if
(exception ===
'timeout'
) { msg =
'Time out error.'
;
19.
}
else
if
(exception ===
'abort'
) { msg =
'Ajax request aborted.'
;
20.
}
else
{ msg =
'Uncaught Error.\n'
+ jqXHR.responseText;
21.
}
22.
alert(msg +
"\r\n"
+
'กรุณาทดลองใหม่'
);
23.
}
24.
});