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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。