我不知道PHP的规格和ID DIV。这是我的问题:
我可以在同一时间输入名为 #modal 的 ID DIV 和 ID PHP RETURN 吗?
while ( $contents_print = mysqli_fetch_array( $req_print ) ) {
echo'
<div class="row print">
<div class="col s12 m4">
<div class="card">
<div class="card-image">
<img data-tags="print" class="activator" src="../00_sources/images/upload/pic_min/' . $contents_print[ 'pic_min' ] . '" alt="' . $contents_print[ 'pic_min' ] . '">
<a href="#modal" class="btn-floating halfway-fab waves-effect waves-light primary-color-text modal-trigger"><i class="material-icons">add</i></a>
</div>
<div class="card-content">
<span class="card-title">'.$contents_print['nom_projet'].'</span>
<p>'.$contents_print['detail_projet'].'</p>
</div>
</div>
</div>
</div>';
}
这是我的jquery ajax代码:
$(document).ready(function(){
$('.materialboxed').materialbox();
});
$( document ).ready( function () {
$.ajax( {
url: 'core/libs/contents-services.php?action=getFilterContent&id=3',
type: "get",
dataType: "html",
success: function ( reponse ) {
$( '#modal' ).html( reponse );
}
} );
// the "href" attribute of the modal trigger must specify the modal ID that wants to be triggered
$( '.modal' ).modal();
} );
在我的ajax代码中:行 url:'core / libs / contents-services.php?action = getFilterContent&amp; id = 3',我必须使用php / mysql中的id请求
我想建立一个这样的链接: url:'core / libs / contents-services.php?action = getFilterContent&amp; id ='。$ _ GET ['id']。',
我希望我很清楚
感谢您的帮助
http://portfolio.rabahbook.fr查看我工作的网站
答案 0 :(得分:0)
据我所知,你从响应中得到一个Id,并尝试将其分配给ajax href。如果是这种情况,您可以执行以下操作(请注意url_id变量。):
var url_id =3;
$( document ).ready( function () {
$.ajax( {
url: 'core/libs/contents-services.php?action=getFilterContent&id='+url_id,
type: "get",
dataType: "html",
success: function ( reponse ) {
$( '#modal' ).html( reponse );
url_id = response.url_id;/// get url id from response and assign it to
//your href
}
});
// the "href" attribute of the modal trigger must specify the modal ID
//that wants to be triggered
$( '.modal' ).modal();
} );
</script>
答案 1 :(得分:0)
$('.post .modal-action').click(function(e){
e.preventDefault();
var id_projet= $(this).data('id_projet');
var $hidennDiv = $('#' +id_projet);
// do your ajax and whatever you want to do with the hidden div
$.ajax( {
url: 'core/libs/contents-services.php?action=getFilterContent&id='+id_projet,
type: "get",
dataType: "html",
success: function ( reponse ) {
$( '#modal' ).html( reponse );
id_projet = reponse.id_projet;
}
} );
$( '.modal' ).modal();
});
这对我有用
<a href="#modal" class="modal-action modal-trigger" data-id_projet="'.$contents_print[ 'id_projet' ].'"></a>
感谢大家抽出时间给我一个人!