在php循环中不更新Ajax响应

时间:2022-11-24 14:26:54

I am having a slight problem figuring out why this ajax response isn't updating properly. I have a php while loop which lists gallerys in text format, i am using . It is getting details from the php page but only for one result so essentially when you hover over the name a qtip tooltip box pops up so you can edit the name of the gallery. The problem is it only lists one result for all results in the loop.

我有一个小问题,弄明白为什么ajax响应没有正确更新。我有一个php while循环,它以文本格式列出gallerys,我正在使用。它从php页面获取详细信息,但只获取一个结果,所以当您悬停在名称上时,会弹出一个qtip工具提示框,以便您可以编辑库的名称。问题是它只列出循环中所有结果的一个结果。

PHP & HTML

PHP和HTML

    <?php
            $MemberGalleriesQuery = $bapcity->query("SELECT * FROM CroMemberRetailGalleries WHERE UserID='".$_SESSION['user_id']."' ORDER BY GalleryID DESC");
            $MemberGalleriesCount = $MemberGalleriesQuery->num_rows;

            if ( $MemberGalleriesCount ) 
            {
                $BaseHeight = 150;
                $GalleriesBoxHeight = $BaseHeight + ( 20 * $MemberGalleriesCount );
                echo '
                <div id="ManageGalleries" style="height: '.$GalleriesBoxHeight.'px" align="center">
                <div id="ManageGalleriesHeader">Manage Galleries</font></div><br><br>
                <font color="#000000"><b>Click Gallery To Edit</b></font><br><br>
                ';

                while($GalleryData = $MemberGalleriesQuery->fetch_assoc())
                {
                    echo '>> <b><a class="EditGallery" href="Crowork.Backend/Crowork.EditGallery.php?action=EditGallery&gallerykey='.$GalleryData['GalleryID'].'">'.$GalleryData['GalleryName'].'</a></b> <<<br>';
                }

                echo '<br><br></div>';
            }
            $MemberGalleriesQuery->free();
            ?>

JAVASCRIPT:

JAVASCRIPT:

    //Edit Form When Hovering Over Gallery Name
$('.EditGallery').each(function() {


    var link = $('.EditGallery').attr('href'); //Gets link url

    $.ajax({ //Make the ajax request
        url: link,
        cache: false
    }).done(function( html ) { //On complete run tooltip code

        //Display tooltip code goes here, returned text is variable html
    $('.EditGallery').qtip({
        content: {
            text: html
        },
        hide: {
            fixed: true,
            delay: 300
        },
        style: 'wiki'
    });
    $('.EditGallery').qtip('click', true);
    $(".EditGallery").page();
    });
});

CONTENTS OF Crowork.Backend/Crowork.EditGallery.php

Crowork.Backend / Crowork.EditGallery.php内容

    if ( isset( $cleanGet['action'] ) && $cleanGet['action'] == 'EditGallery' ){

    $MemberGalleriesQuery = $bapcity->query("SELECT * FROM CroMemberRetailGalleries WHERE GalleryID='".$cleanGet['gallerykey']."' AND UserID='".$SessionUserID."' ORDER BY GalleryID DESC");

    $MemberGalleriesCount = $MemberGalleriesQuery->num_rows;

    if ( $MemberGalleriesCount )
    {       
        $GalleryData = $MemberGalleriesQuery->fetch_assoc();
    }?>

    <form action="Crowork.Backend/Crowork.EditGallery.php?action=DoEditGallery&gallerykey=<?php echo $GalleryData['GalleryID']?>" method="post">
        <input type="hidden" name="GalleryName" value="<?php echo $GalleryData['GalleryName']?>">
        <input type="hidden" name="GalleryID" value="<?php echo $GalleryData['GalleryID']?>">
        <input type="submit" name="DeleteGallery" value="Delete Gallery">
    </form>

    <form action="Crowork.Backend/Crowork.EditGallery.php?action=DoEditGallery&gallerykey=<?php echo $GalleryData['GalleryID']?>" method="post">
    <table border="0" width="100%">
    <tr>
        <td colspan="2" align="center"><font size="-1"><b>NOTE:</b> Letters & Numbers Only</font></td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><input type="text" name="GalleryName" size="30" value="<?php echo $GalleryData['GalleryName']?>"></td>
    </tr>
    <tr>
        <td align="right" colspan="2">
            <input type="hidden" name="OriginalGalleryName" value="<?php echo $GalleryData['GalleryName']?>">
            <input type="hidden" name="GalleryID" value="<?php echo $GalleryData['GalleryID'] ?>">
            <input type="submit" name="EditGallery" value="Edit Gallery">
        </td>
    </tr>
    </table>
    </form>
    <?php }?>

PREVIEW:

预览:

http://www.bigjohn863.com/mini-upload-form/uploads/ajaxproblem.png

http://www.bigjohn863.com/mini-upload-form/uploads/ajaxproblem.png

See how all three are the same results.

看看这三个结果是怎样的。

3 个解决方案

#1


1  

Try:

试一试:

 $('.EditGallery').each(function()
{
        $(this).qtip({
        content:  {
            text: "Loading...",
            ajax: {
                url:$(this).attr('href'),
                type: "GET",
                success: function(data, status) {
                  this.set('content.text', data);
                }                
               }

            },
        hide: {
            fixed: true,
            delay: 300
        },
        style: 'wiki'
    });
    $(this).qtip('click', true);
});

http://jsfiddle.net/st0j8nLy/

http://jsfiddle.net/st0j8nLy/

#2


1  

//Edit Form When Hovering Over Gallery Name
$('.EditGallery').each(function() {

var link = $('.EditGallery').attr('href'); //Gets link url
....

everytime you are calling $('.EditGallery'). $('.EditGallery'). is an array, you need to change all references to $('.EditGallery') that is within the loop to $(this):

每次您调用$('. editgallery ')时。$(' .EditGallery ')。是一个数组,您需要将循环中的所有对$(this)的引用更改为$('.EditGallery'):

var link = $(this).attr('href'); //Gets link url

#3


1  

You Might be need to create dynamic id so you can call proper ajax. please modify your ajax call as below

您可能需要创建动态id,以便调用合适的ajax。请修改您的ajax调用,如下所示

 $gid=$GalleryData['GalleryID'];              
 echo '>> <b><a onclick="editgalary($gid)" id="EditGallery_$gid" href="Crowork.Backend/Crowork.EditGallery.php?action=EditGallery&gallerykey='.$GalleryData['GalleryID'].'">'.$GalleryData['GalleryName'].'</a></b> <<<br>';

replace this code in while loop.

在while循环中替换此代码。

function editgalary(galaryid){
   var link = $('#EditGallery_'+galaryid).attr('href');
//ajax code as it is.
}

try and let me konw

试着让我知道

#1


1  

Try:

试一试:

 $('.EditGallery').each(function()
{
        $(this).qtip({
        content:  {
            text: "Loading...",
            ajax: {
                url:$(this).attr('href'),
                type: "GET",
                success: function(data, status) {
                  this.set('content.text', data);
                }                
               }

            },
        hide: {
            fixed: true,
            delay: 300
        },
        style: 'wiki'
    });
    $(this).qtip('click', true);
});

http://jsfiddle.net/st0j8nLy/

http://jsfiddle.net/st0j8nLy/

#2


1  

//Edit Form When Hovering Over Gallery Name
$('.EditGallery').each(function() {

var link = $('.EditGallery').attr('href'); //Gets link url
....

everytime you are calling $('.EditGallery'). $('.EditGallery'). is an array, you need to change all references to $('.EditGallery') that is within the loop to $(this):

每次您调用$('. editgallery ')时。$(' .EditGallery ')。是一个数组,您需要将循环中的所有对$(this)的引用更改为$('.EditGallery'):

var link = $(this).attr('href'); //Gets link url

#3


1  

You Might be need to create dynamic id so you can call proper ajax. please modify your ajax call as below

您可能需要创建动态id,以便调用合适的ajax。请修改您的ajax调用,如下所示

 $gid=$GalleryData['GalleryID'];              
 echo '>> <b><a onclick="editgalary($gid)" id="EditGallery_$gid" href="Crowork.Backend/Crowork.EditGallery.php?action=EditGallery&gallerykey='.$GalleryData['GalleryID'].'">'.$GalleryData['GalleryName'].'</a></b> <<<br>';

replace this code in while loop.

在while循环中替换此代码。

function editgalary(galaryid){
   var link = $('#EditGallery_'+galaryid).attr('href');
//ajax code as it is.
}

try and let me konw

试着让我知道