简体   繁体   English

将值从jquery发送到php

[英]Send value from jquery to php

I have a web page that displays several albums and the following html code for an album icon that should allow the user to change the access settings to the specific album ($row holds the response values from a db query that returns info on albums) 我有一个网页,其中显示了几个相册,并且以下html图标代码显示了相册图标,该图标应允许用户更改对特定相册的访问设置($ row保留来自数据库查询的响应值,该查询返回有关相册的信息)

<a data-title="'.$row['title'].'" data-description="'.$row['description'].'" data-id="'.$row['photoCollectionId'].'" class="open-update_dialog2" data-toggle="modal" href="#update_dialog2">
 <i class="ace-icon fa fa-eye"></i>
</a>

and if the user clicks on it, a modal shows up 如果用户单击它,则会显示一个模式

<div class="modal fade" id="update_dialog2" role="dialog">
 <div class="modal-dialog">
  <div class="modal-content">
   <ul id="check-list-box" class="list-group checked-list-box">
     <?php
      foreach (getFriends($email) as $row) {
      $flag = checkAccessRights($row['email'],1)['value'];
      echo '<li class="list-group-item" data-checked='.$flag.'>'.$row['firstName'].' '.$row['lastName'].'</li>';
      }
     ?>
  </ul>  
 </div>
</div>
</div>

.js .js文件

$(document).on("click", ".open-update_dialog2", function () {
     albumName = $(this).data('title');
     $(".modal-body #albumName").val(albumName);
     albumDescription = $(this).data('description');
     $(".modal-body #albumDescription").val(albumDescription);
     albumId = $(this).data('id');

});

My problem is that each modal would need to fetch different data depending on the album the user clicked on and thus I want to replace the value of 1 in checkAccessRights($row['email'],1) with the value of the variable albumName . 我的问题是,每个模式都需要根据用户点击,因此我要替换的值专辑来获取不同的数据1checkAccessRights($row['email'],1)与变量的值albumName Is there a way to get the value from jquery to php? 有没有办法将值从jquery转换为php? Any tip would be greatly appreciated! 任何提示将不胜感激!

You can use ajax , 您可以使用ajax

This (Ajax) help you to create dynamic album. 此(Ajax)帮助您创建动态相册。

JQuery it is a client side, PHP it is a server. jQuery是客户端,PHP是服务器。 So you should send request to the server with albumId parameter. 因此,您应该使用albumId参数将请求发送到服务器。

$(document).on("click", ".open-update_dialog2", function () {
    albumName = $(this).data('title');
    $(".modal-body #albumName").val(albumName);
    albumDescription = $(this).data('description');
    $(".modal-body #albumDescription").val(albumDescription);
    albumId = $(this).data('id');

    $.get("yourPhpFile.php", {albumId:albumId}).done(function(resp) {
       // 
    });

});

and on your server you need get this parameter and put in your loop 在您的服务器上,您需要获取此参数并放入循环中

<div class="modal fade" id="update_dialog2" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <ul id="check-list-box" class="list-group checked-list-box">
       <?php
         $albumId = $_GET['albumId'] ? $_GET['albumId'] : 1;
         foreach (getFriends($email) as $row) { 
           $flag = checkAccessRights($row['email'], $albumId)['value'];
           echo '<li class="list-group-item" data-checked='.$flag.'>'.$row['firstName'].' '.$row['lastName'].'</li>';
          }
        ?>
      </ul>  
   </div>
 </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM