douzhangwei5265 2015-02-08 20:38
浏览 25
已采纳

空间破坏了jQuery中的img src

Basically the title.

I have a mysql query:

while ($array = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    $jsonData[] = $array;
}
echo json_encode($jsonData);    

A variable referencing a value that has spaces in it named "Remnant of Argus":

var pname = value.Pet_Name;    

that is being used to insert the value into both a plaintext <div> and an image style='background-image: url():

$("img#"+char).click(function(){
    $("#charlist").html(title
           +"<table style='background:#888' width='600px'>"
             +"<tr>"
               +"<td rowspan='4' height='150px' width='150px' style='background-image: "
                       +"url(/images/char/"+char+".png)'></td>"
               +"<td>Name: "+fname+" "+lname+"</td>"
               +"<td>Class: "+spec+" "+role+"</td>"
             +"</tr>"
             +"<tr>"
               +"<td>Race: "+race+"</td>"
               +"<td>Rank: "+rank+"</td>"
             +"</tr>"
             +"<tr>"
               +"<td>Height: "+height+"</td>"
               +"<td>Weight: "+weight+"</td>"
             +"</tr>"
             +"<tr>"
               +"<td>Age: "+age+"</td>"
               +"<td>Birthplace: "+birth+"</td>"
             +"</tr>"
           +"</table>"
           +"<table width='600px'>"
             +"<tr>"
               +"<td>Bio:<br />"+bio+"</td>"
             +"</tr>"
           +"</table>"
           +"Pets"
           +"<table class='"+pname+"' width='300px'>"
             +"<tr>"
               +"<td rowspan='2' height='150px' width='150px' style='background-image: "
                       +"url(/images/pets/"+pname+".png)'></td>"
               +"<td>Name: "+pname+"</td>"
             +"</tr>"
             +"<tr>"
               +"<td>Species: "+prace+"</td>"
             +"</tr>"
           +"</table>"
           +"<table width='300px'>"
             +"<tr>"
               +"<td rowspan='2' height='150px' width='150px' style='background-image: "
                       +"url(/images/battlepets/"+cname+".png)'></td>"
               +"<td>Name: "+cname+"</td>"
             +"</tr>"
             +"<tr>"
               +"<td>Species: "+crace+"</td>"
             +"</tr>"
           +"</table>");

    $("table.none").hide();
});    

Everything shows up fine except for the image. I've added backslashes to both the filename and value and THEN it shows up fine. I've tried everything I can think of, to replacing the spaces in the MySQL call (just adds backslashes everywhere), tried replacing the character in my jQuery (either breaks it completely or just plain doesn't work), adding another variable for just this one instance and trying encodeURIComponent or replace to no avail, and I'm at my wit's end.

I was hoping to not have to add another column of values without spaces JUST for background-image source URL, but if that's what it comes down to, I'll just do it and say screw it.

Any advice on what I'm doing wrong? If you need any other pertinent info, lemme know. The website is: http://wow.zenakrua.com/ and you click Windwalkers, then click the angry purple chick, middle of the second row.

  • 写回答

1条回答 默认 最新

  • douyin2883 2015-02-08 21:10
    关注

    That image doesn't exist. If it did, you would be able to access it using this URL on the browser:

    wow.zenakrua.com/images/battlepets/Remnant%20of%20Argus.png

    The image name is either wrong, or you need to change the permissions on it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器