안녕하세요, msg를 undefined로 반환하는이 스크립트가 있습니다. consol에서는 jsondata를 반환하지만 경고를하거나 확인하려고 할 때 작동하지 않습니다.ajax success : function (msg) undefined
$(function() {
$(".aplica_bt").click(function(e) {
e.preventDefault();
var href = $(this).attr('href');
$.ajax({
url: href,
datatype: "json",
success: function(msg) {
alert(msg.exista);
if (msg.exista == "yes") {
alert('ai aplicat');
}
if (msg.aplicat == "yes") {
$('#modal_succes').modal('show');
}
},
});
});
});
도 여기에 JSON을
<?php
$id_c=$_GET['id_c'];
$id_j=$_GET['id_j'];
$stmt=$dbh->prepare("SELECT * FROM Aplicatii where id_c=:id_c and id_j=:id_j");
$stmt->bindParam(":id_c",$id_c);
$stmt->bindParam("id_j",$id_j);
$stmt->execute();
if($row=$stmt->fetch())
{
$arr = array('exista' => 'yes');
echo json_encode($arr);
}
else
{
$stmt=$dbh->prepare("INSERT INTO Aplicatii (id_c,id_j) VALUES (:id_c,:id_j)");
$stmt->bindParam(":id_c",$id_c);
$stmt->bindParam("id_j",$id_j);
$stmt->execute();
$arr = array('aplicat' => 'yes');
echo json_encode($arr);
}
?>
그리고 console.log
의 응답을 반환 PHP 코드입니다 :
{"exista":"yes"}
'을 console.log (MSG) 무엇을 않습니다 구문 분석하는 것입니다? – eisbehr
'{ "exista": "yes"}' – chris227
그래서 '객체'가 아닌'문자열 '을 반환합니까? 그렇다면'msg.exista'는'undefined '가되어야합니다. – eisbehr