dongshao1021 2011-01-29 06:10
浏览 51
已采纳

jquery加载不读取字符串作为变量(php hybrid)

I'm writing out a javascript string to be parsed by jquery - it works fine as an alert but not in the jquery load function

PHP:

$imgData = 'http://www.domain.com/_image.php/_MG_4156.jpg'  ;

which is a php script to generate a thumbnail on the fly

<script type='text/javascript' language='javascript' charset='utf-8'>
<!--
    var chart1img_".$i_gall." = new Image();
    var imgData   = '".$imgData."';

    $(chart1img_".$i_gall.").load(function () {
        $(this).hide();
        $('#thumb_img_div_".$i_gall."').removeClass('loading').append(this);
        $(this).fadeIn();
    }).error(function () {
        // notify the user that the image could not be loaded
        alert(imgData);
    }).attr('src', imgData); 
  //}).attr('src', 'http://www.domain.com/_image.php/_MG_4156.jpg'); 

//-->
</script>";

If I hardcore the string it works. If I use it as the imgData variable it fails, but the alert works using imgData

Tried string combos all ways. Defeated. Any ideas?

  • 写回答

3条回答 默认 最新

  • duanhan8757 2011-01-29 07:29
    关注

    Not sure what the problem is other than it's one of the characters in the full variable?:

    var imgData   = 'http://www.domain.com/_image.php/".$r_gall['image']."?width=145&height=205&cropratio=145:205&image=/images_cms/".$r_gall['image']."';
    

    But I kept as much of the string in JS and just replaced the dynamic parts with PHP

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

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型