空间破坏了jQuery中的img src

时间:2015-02-08 20:38:06

标签: php jquery mysql ajax backslash

基本上是标题。

我有一个mysql查询:

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

引用其中包含空格的值的变量名为" 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中的字符(要么完全破坏它,要么只是简单地不工作),为这一个实例添加另一个变量并尝试使用encodeURIComponent或替换为无效,我在我的智慧结束时。

我希望不必为background-image源网址添加另一列值而没有空格JUST,但是如果这就是它所涉及的内容,我只会这样做并说出来搞砸了。

关于我做错的任何建议?如果您需要任何其他相关信息,请知道。该网站是:http://wow.zenakrua.com/,你点击Windwalkers,然后点击第二排中间的愤怒的紫色小鸡。

1 个答案:

答案 0 :(得分:0)

该图像不存在。如果是,您可以在浏览器上使用此URL访问它:

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

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