duanhe7471 2012-08-10 21:44
浏览 42
已采纳

使用Ajax从PHP数组交换图像并获取ID

On my website an user is able to fill in an url. When he fills in the url, he gets all the images src's from that url. I push these src's to an array in php:

 array_push($goodfiles,$pic);

Now the user will be able to choose on of the pictures (with a next or prev button) and then save it to the database. The picture that's saved is based on the id of the image in the array. So $goodfiles['0'] means id = "0" and so on.

I want the swapping of the images to work with ajax, so that the pages doesn't have to refresh all the time when clicking the next or previous button. And then when I save the form, I want to know the id of the current image, so that I can save it to the database.

How do I realize this with Ajax (jquery)?

Edit:

This is how I do it right now:

    $current_id = $_GET['id'];
if(empty($_GET['id']) || !empty($empty)) { $current_id = 0; }
$prev_id = $_GET['id'] - 1;
if($prev_id < 0){ $prev_id = 0;}
$next_id = $_GET['id'] + 1;
if($next_id > $_SESSION['count']-1 && $_SESSION['count'] != 'empty') { $next_id = $_SESSION['count']-1;}

This is the code for the pagination

And this is the pagination:

        <div id="url_pic">

        <img src="<?=$_SESSION['pictures'][$current_id]?>" class="img_load"><br>
        <? if($_SESSION['count'] > 1) { ?><center><a href="additem_url.php?id=<?=$prev_id?>"><img src="img/add/left.png"></a> <a href="additem_url.php?id=<?=$next_id?>"><img src="img/add/right.png"></a></center> <? } ?>

    </div>

So right now my solution doesn't contain any javascript, but it's all php coded. And the page refreshes everytime you want to see the next picture. I want to solve this in ajax, so that you can paginate through the images without a refresh. The way I want it is like this link:

 http://d-scribe.de/webtools/jquery-pagination/demo/demo_options.htm

But except for the text, I want to paginate through images.

  • 写回答

2条回答 默认 最新

  • douzao5487 2012-08-10 22:20
    关注

    You probably don't need to use AJAX for this. Simply return a html file containing a JavaScript array, which contains all those image URLs and do the other stuff using JavaScript.

    Get back to StackOverflow in case you've a more precise question and hopefully some code, which we can help on ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行