c# - 如何从 XML 向 <img> 提供图像源?

标签 c# javascript jquery asp.net sql

我正在向下滚动加载中继器。我正在尝试显示消息发件人的名称、消息和发件人的图像缩略图。除了图像之外,一切都工作正常。我将图像的名称/路径视为文本而不是图像本身。

[WebMethod]
    public static string GetCustomers(int pageIndex, int qstr)
    {
        return GetCustomersData(pageIndex,qstr).GetXml();
    }

XML

<Customers>
        <RowNumber>11</RowNumber>
        <MsgId>12</MsgId>
        <sentby>Matt</sentby>
        <sentTo>John</sentTo>
        <Msg>ok?</Msg>
        <ImageName>935604602.jpg</ImageName>
      </Customers>

现在我在 aspx 上有这个代码..

function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
        var customers = xml.find("Customers");
        customers.each(function () {
            var customer = $(this);
            var table = $("#dvCustomers table").eq(0).clone(true);
            $(".MsgId", table).html(customer.find("MsgId").text());
            $(".sentby", table).html(customer.find("sentby").text());
            $(".sentTo", table).html(customer.find("sentTo").text());
            $(".Msg", table).html(customer.find("Msg").text());
            $(".ImageThumb", table).html(customer.find("ImageUrl").text());
 $("#dvCustomers").append(table).append("");
        });
        $("#loader").hide();
    }

中继器代码

   <asp:Repeater ID="rptCustomers" runat="server" >
        <ItemTemplate>
            <table cellpadding="0" cellspacing="0" border="0" style="width: 400px; height: 50px;
            border: dashed 0px #04AFEF; background-color:#F1EEE5">
            <tr>
                <td>
                    <b><u><span class="sentby" style="color:#A52A2A;"><%# Eval("sentby") %></span></u></b>
                </td>
            </tr>
            <tr>
                <td>                       
                    <b> <span class="ImageThumb"><img src= "<%# Eval("ImageUrl") %>" alt="Title #0" width="70" height="70" /></a></b></span> 
                                        <span class="Msg"><%# Eval("Msg")%></span>                                          
                </td>
            </tr>
        </table>

        </ItemTemplate>
    </asp:Repeater>
  </div>

除了图像之外,一切正常。我在文本中看到图像的名称/路径,而不是图像本身。

最佳答案

试试这个

$(".ImageThumb > img", table).attr('src', customer.find("ImageUrl").text());

您的 XML <ImageName> 之间也可能不匹配。和你的 jQuery find("ImageUrl")

关于c# - 如何从 XML 向 <img> 提供图像源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212655/

相关文章:

javascript - <select> for <select> c# 到 javascript

javascript - 响应式菜单不会滚动到右侧的 div,而是滚动到页面顶部

c# - string.IsNullOrEmpty & string.IsNullOrWhiteSpace 为空字符串返回 false

C# .net 4 十进制到字符串考虑点后的数字

c# - 使用 Azure Function V1 时,Azure 存储文件共享 dll 在运行时导致 runtime.compiler.unsafe 错误

javascript - 无法在 iOS 设备上设置新的谷歌翻译 cookie 值

javascript - 如何在 javascript 中使用正则表达式来匹配此特定字符串,如果匹配则将其设为空

javascript - 如何保持方法直到数组在mongodb中有2个元素

c# - 系统.诊断.进程参数

php - 获取远程数据 - PHP 还是 JavaScript?