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

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了