MySQL 데이터베이스에 대한 쿼리를 처리하도록 설계된 PHP 파일을 사용하는 AJAX 페이지 요청이 있습니다. PHP 파일은 정상적으로 작동하지만, 어떤 이유로 그것은 나와 잘 맞지 않습니다. 여기에 내가 가진 무엇 :JSON 객체가 정의되지 않았습니다.
이{"results":[{"ID":"12","area":"Hoboken","bedrooms":"5","fullbath":"3","halfbath":"1","remarks":"No remarks to speak of.","sqft":"2500","photos":null,"price":"1000","fee":null,"realtor":"Jane Doe","phone":"555-555-5555","address":"10th & Willow","bix":"1"}]}
하지만 최대한 빨리으로 변경으로 :
function updateForm(){
ID = $('#listings').val();
$.ajax({
type: "POST",
url: 'query.php',
data: "query=true" +
"&id=" + ID,
datatype: 'json',
success: function(data) {
alert(data.results);
updatePreview();
}
});
}
팝업 바로 정의되지 않은 말한다
function updateForm(){
ID = $('#listings').val();
$.ajax({
type: "POST",
url: 'query.php',
data: "query=true" +
"&id=" + ID,
datatype: 'json',
success: function(data) {
alert(data);
updatePreview();
}
});
}
과 함께 나에게 팝업을 제공합니다.
궁극적으로 정보를 분석하고 이에 따라 페이지를 업데이트하고 싶지만이 JSON 개체의 속성에 액세스 할 수없는 것 같습니다. 무슨 일이야?
편집 :
여기 PHP 파일의 코드입니다 :
if (isset($_POST['query'])){
if (isset($_POST['id'])){
$query = 'SELECT * FROM bix WHERE ID=' . get_post('id');
$listing = mysql_query($query);
print_json($listing);
}
}
function print_json($var){
$output = array();
while($row = mysql_fetch_assoc($var)) {
$output["results"][] = $row;
}
echo json_encode($output);
}
function get_post($var)
{
return mysql_real_escape_string($_POST[$var]);
}
서버 측 코드를 게시 할 수 있습니까? –
만약 당신이 console.log() 둘 다 얻는다면? –
어쩌면 당신은 T를 대문자로 dataType ... – Timmerz