Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jCarousel通过Ajax动态加载内容_Php_Javascript_Jquery - Fatal编程技术网

Php jCarousel通过Ajax动态加载内容

Php jCarousel通过Ajax动态加载内容,php,javascript,jquery,Php,Javascript,Jquery,我尝试做一个滑块并从php文件动态加载数据,我从数据库中获取图像,但我现在有问题链接这个图像 这是我的php文件ajax_php.php 这是js function mycarousel_itemLoadCallback(carousel, state) { // Check if the requested items already exist if (carousel.has(carousel.first, carousel.last)) { return;

我尝试做一个滑块并从php文件动态加载数据,我从数据库中获取图像,但我现在有问题链接这个图像

这是我的php文件ajax_php.php

这是js

function mycarousel_itemLoadCallback(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'ajax_php.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{

     // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));

    });
};


function mycarousel_getItemHTML(url)

{ 
    return '<img src="' + url + '" width="75" height="75" alt="" />';
};

jQuery(document).ready(function() {
    jQuery('#futuredbc').jcarousel({

  easing: 'BounceEaseOut',
         itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
        itemLoadCallback: mycarousel_itemLoadCallback
    });
});
这个方法支持我的结果像

<img width="75" height="75" alt="" src="img.jpg">
但我需要制作一个像这样的链接图像

<a href="http://site.com/548"><img width="75" height="75" alt="" src="img.jpg"></a>

所以site.com/548是一个i ID,我可以从数据库中获取它。$row['ID']。但是我不知道如何使js和link result成为最简单的方法,而无需添加函数来解析另一个XML标记 要将ID添加到图像xml标记的值中并使用分隔符,我们将从url中拆分ID

将行ID添加到数组中:

while(($row =  mysql_fetch_assoc($res))) {
    $images[] = array('id' => $row['id'] , 'src' => '/images/'.$row['img_i'].'');
}
将其打印到XML:

foreach ($selected as $img) {
    echo '<image>' . $img['src'] . '|||'.$img['id'].'</image>';
} 
然后,重新安装:

return '<img src="' + url + '" width="75" height="75" alt="" />';
与:

应该有用。
否则,请发表评论,我会修复它。

Hmm但无法使用echo$img['src'].| | | |'$img['id']。;现在更新我的答案。现在看第一部分。
return '<img src="' + url + '" width="75" height="75" alt="" />';
var tmp = url.split('|||');

return '<a href="www.site.com/'+ tmp[1] +'"><img src="' + tmp[0] + '" width="75" height="75" alt="" /></a>';