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条)

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂