此代码适用于localhost,但不适用于真实的Chrome开发人员工具,显示该值已发送,状态代码:200 OK。但该值未达到php页面。 关于mozilla开发人员工具说json.PARSE:意外的无空白。但是在文本或空格之前和之后都没有任何内容。 我在同一文件夹中的所有文件。
$(document).ready(function(){
// sending id from portfolio to ajax for display modal carousel
$('.view').on('click', function(e){
var id2 = $(this).find('a').attr('id');
$('.getValueHere').empty(); // empty the div before fetching and adding new data
$.ajax({
type: "POST",
url: "ajax.php",
data: { 'id': id2 },
success: function(data){
$('.getValueHere').append(data.result);
},
error: function(){
alert("error");
}
});
});
});
这里是php页面
header("Content-Type: application/json; charset=UTF-8");
include_once("database/db.php");
$db = new connection();
$db = $db->dbConnection();
/*******************************************************************
* This is for ADD new image on ADD image page, creating image with ajax
* portfolio carousel img
********************************************************************/
$id = $_POST["id"]; // this post id never comes here
$check = $db->prepare("SELECT * FROM website_articles where id='".$id."'");
$check->execute();
$result = array();
while($row = $check->fetch(PDO::FETCH_ASSOC)) {
// SLIDE IMAGE
$image = $row['img_url_slider'];
$image = explode(',',$image);
// SLIDE TECHNIQS
$tech = $row['teknologies'];
$tech = explode(',',$tech);
$name = $row['article_name'];
$desc = $row['article_description'];
$result['result'] ="";
$result['result'] .= '<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="gridSystemModalLabel" style="margin-left:15px;">'.$name.'</h4>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="wrapper" style="margin-bottom:30px;">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">';
for($i=0; $i<count($image); $i++){
if($i == 0){
$result['result'] .= '<li data-target="#carousel-example-generic" data-slide-to="'.$i.'" class="active"></li>';
}else{
$result['result'] .= '<li data-target="#carousel-example-generic" data-slide-to="'.$i.'" class=""></li>';
}
}
$result['result'] .= '</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox"> ';
for($i=0; $i<count($image); $i++){
if($i == 0){
$result['result'] .='
<div class="item active">
<img src="'.@$image[0].'" alt="..." class="img-responsive">
<div class="carousel-caption"> </div>
</div>';
}else{
$result['result'] .='
<div class="item">
<img src="'.@$image[$i].'" alt="..." class="img-responsive">
<div class="carousel-caption"></div>
</div>';
}
}
$result['result'] .= '</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- /carousel-->
</div>
<div class="col-md-6 col-lg-6">
<h3>Technologies</h3>
<ul class="list-unstyled checkList">';
for($i=0; $i<count($tech); $i++){
$result['result'] .= '<li><i class="fa fa-check"></i> '.$tech[$i].'</li>';
}
$result['result'] .= '</ul>
</div>
<div class="col-md-6 col-lg-6">
<h3>Description</h3>
<p>'.html_entity_decode($desc).'</p>
</div>
</div><!-- /row-->
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
<a type="button" href="'.$row['article_url'].'" target="_blank" class="btn btn-primary">visit website</a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>';
}
$result = json_encode($result);
echo $result;
&GT;
答案 0 :(得分:0)
删除它并查看错误是否消失。
html_entity_decode($desc)
如果它消失,请尝试:
html_entity_decode($desc,ENT_QUOTES)
答案 1 :(得分:0)
可能是因为您的标头已在其他位置设置。您是否尝试注释掉标题以查看是否可以解决问题?同时启用php错误以显示不允许代码继续的任何隐藏错误。希望这会有所帮助!