안녕하세요, 저는 아약스를 통해 PHP 스크립트에 연결하는 자바 스크립트 코드가 있습니다. 이 PHP 스크립트는 배열을 반환합니다. ajax 호출의 성공 함수에서 반환 된 배열을 사용하여 정보를 사용자에게 표시합니다. 이 모든 것은 Internet Explorer를 제외한 모든 브라우저에서 잘 작동합니다. 다음 오류가 발생합니다.Javascript/PHP JSON Array IE에서 null
Unable to get property '0' of undefined or null reference
'0'은 배열의 첫 번째 요소의 인덱스입니다.
JS
$.ajax({
type: "POST",
url: "/add.php",
data: 'id=' + itemid,
dataType: "json",
success: function (data) {
document.getElementById("name").innerHTML = data[0];
document.getElementById("desc").innerHTML = data[1];
document.getElementById("price").innerHTML = data[2];
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
PHP 내가 성공 기능과 그것이 배열을 돌려 다른 브라우저 반면, null를 돌려 Internet Explorer에서 console.log(data)
을 시도
$output = array();
$output[0] = $itemname;
$output[1] = $itemdescription;
$output[2] = $itemprice;
echo json_encode($output);
exit();
: 여기에 코드입니다. 아무도 여기서 무엇이 잘못되었는지 압니까?
EDIT : IE의 콘솔에있는 오류 코드는 SCRIPT5007입니다. 이 검색되면,이 의미
You attempted to invoke the Object.prototype.toString or Object.prototype.valueOf method on an object of a type other than Object. The object of this type of invocation must be of type Object.
출력에서 봐 내 질문에 다시 코드 블록에서 실수의 모습이 있었다 http://codepad.org/7quG3IKs – Musa