저는 아약스의 POST 요청을 받아들이고 응답을 되돌려주는 PHP 스크립트를 작성했습니다. 모두 잘 작동합니다. 그러나 문자를받는 문자 분할 문자는 이유가 무엇인지 이해할 수 없습니다. 'ImagePath를' 하지만 편지에 의해 분할 편지로 출력을주고있다 :JSON 값이 제대로 표시되지 않습니다.
여기
$("#btn").click(function(){
console.log($("#search_bar").val());
var dataV;
var htmlText = '';
var containerbootsrap = '';
var filename = '';
var index_no;
$.ajax({
type: "POST",
crossDomain: true,
url: "http://localhost:8090/ontology/setText",
data: $("#search_bar").val(),
contentType: 'text/plain',
// dataType: "json",
success: function(data, textStatus, jQxhr){
console.log('data');
console.log(data);
for(var item in data) {
console.log ("item: " + item);
console.log ("data: " + data[item]);
index_no = data[item];
// htmlText += '<div class="div-conatiner">';
// htmlText += '<p class="p-name"> Name: ' + data[item] + '</p>';
// htmlText += '<img class="imageload" src="' + data[item] + '" />';
// htmlText += '</div>';
// filename = data[item].replace(/^.*[\\\/]/, '')
$.ajax({
data: 'index_no=' + index_no,
url: 'retrivedata.php',
method: 'POST', // or GET
dataType: 'json',
success: function(msg) {
console.log(msg);
for(var item in msg){
console.log ("item: " + item);
console.log ("data: " + msg[item]);
}
$('#home').hide();
containerbootsrap += '<div class = "container" id="search_container">';
containerbootsrap += '<div class = "row homepage">';
containerbootsrap += '<div class = "col-md-5 col-md-offset-3">';
containerbootsrap += '<a href="#" class="thumbnail">';
containerbootsrap += '<img class="imageload" src="' + msg + '" />';
containerbootsrap += '<h3 id="video_name"> ' + filename + ' </h3>'
containerbootsrap += '</a>';
containerbootsrap += '</div>';
containerbootsrap += '</div>';
containerbootsrap += '</div>';
$('body').append(containerbootsrap);
}
});
// $.post('retrivedata.php', { num: 5 }, function(result) {
// alert(result);
// });
// $('#home').hide();
}
// $('body').append(containerbootsrap);
},
error: function(jqXhr, textStatus, errorThrown){
console.log(jqXhr);
alert(jqXhr)
}
});
});
PHP 코드는 내가로 출력을 필요
<?php
$index_no = $_POST["index_no"];
// echo $index_no * 2;
include('dbConnection.php');
$query = mysql_query("SELECT * FROM video_data WHERE index_no = $index_no");
while ($row = mysql_fetch_assoc($query)) {
$imagePath = $row['thumbnail_url'];
$videoPath = $row['video_url'];
// echo $imagePath;
// echo $videoPath;
echo json_encode($imagePath);
}
?>
아래, 내 AJAX 코드입니다.
여기에 실제 출력
에게 있습니다하지만 난 한 줄의 출력이 필요합니다. like /video_frames/bb/frame136.jpg 내가 잘못 가고있는 곳을 찾아 내도록 도와주세요.
당신은 출력을 게시 할 수 있습니까? 그리고 단지 팁, 당신은 브라우저에서'header ("Content-Type : application/json");로 기대할 수있는 것을 PHP로 알려줄 수 있습니다; –
'echo json_encode $ imagePath);'while while, 그리고 만약 당신이 단지 하나의 행을 기대하고 있다면'while'을 쓸 필요가 없습니다. –
제가 기억한다면 json_encode는'string'을 제시 할 때 예측할 수없는 결과를냅니다. 그 문자열을'array ($ imagePath)'와 같은 배열에 넣을 수 있습니까? – Forbs