jQuery 中的 img src 空格

Spaces breaking img src in jQuery

基本上是标题。

我有一个mysql查询:

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

引用其中包含空格的值的变量名为 "Remnant of Argus":

var pname = value.Pet_Name;    

用于将值插入纯文本 <div> 和图像 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();
});    

除了图像,一切都很好。我在文件名和值中都添加了反斜杠,然后显示正常。我已经尝试了我能想到的一切,替换 MySQL 调用中的空格(只是在各处添加反斜杠),尝试替换我的 jQuery 中的字符(要么完全破坏它,要么只是简单地不' t work),仅为这个实例添加另一个变量并尝试 encodeURIComponent 或 replace 无济于事,我束手无策。

我希望不必只为 background-image 来源 URL 添加另一列没有空格的值,但如果这就是它的结果,我会这样做并说搞砸了。

对我做错了什么有什么建议吗?如果您需要任何其他相关信息,请告诉我。该网站是:http://wow.zenakrua.com/ 然后您单击 Windwalkers,然后单击第二行中间的愤怒的紫色小鸡。

该图像不存在。如果是这样,您将能够在浏览器上使用此 URL 访问它:

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

图片名称错误,或者您需要更改其权限。