【问题标题】:how to combine an id div and a php id如何结合 id div 和 php id
【发布时间】:2017-11-17 23:37:15
【问题描述】:

我不知道 PHP 和 ID DIV 的规范。这是我的问题:

我可以同时输入一个名为 #modalID 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&id=3', 行我必须使用 php/mysql 请求中的 id

我想建立一个这样的链接: url: 'core/libs/contents-services.php?action=getFilterContent&id='.$_GET['id'].',

我希望我很清楚

感谢您的帮助

http://portfolio.rabahbook.fr查看我的工作网站

【问题讨论】:

标签: php jquery html mysql ajax


【解决方案1】:

据我了解,您从响应中获得了一个 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>

【讨论】:

  • 这段代码一点也不差!但事情是我无法获得与mysql请求相对应的id。当我单击 href 链接时,我想将 id 和模态 id 放在一起。通过这种方式,我可以在名为#modal 的弹出窗口中打印不同的信息。可能我解释的不是很好
【解决方案2】:
$('.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>

感谢大家花时间回复我!

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签