0

我想在隐藏值和 div 中显示 ajax 的成功结果。但它显示在一个或另一个

<input type="hidden" runat="server" ID="piechartval" value="HERE" />
   <div class="rankadvancement "><img src="Assets/Images/imgLoading.gif" style="width: 16px;" />HERE<div>

here is my javacript:

 success: function(data) {
 //var $response = $(data);
                        //oGlobal = $response.find('#pie').text()
                        //alert(oGlobal);
                        var selector ="";
                        var control = '<%=piechartval.ClientID%>';
                        var str = data;
                        var n =str.lastIndexOf('</span>');
                        n = n.replace("</span>","");
                        var a = str.substring(n + 1,str.length - 6);
                        alert(a);
                        document.getElementById(control).value = a; ----- this value in hidden
                        $(selector).html('').html(a);  
                        $('.rankadvancement').html(data); --- this one in div
                    }

谢谢!!

我修改了我的结果,现在我想查看隐藏值的整个结果。但它只在输出中显示这部分,尽管隐藏变量具有完整值(

<div class='col-sm-4'>
                       <div class='pie-chart1 pie-chart pie-number easyPieChart' data-percent=33% style='width: 220px; height: 220px; line-height: 220px;'>33% <canvas width='220' height ='220'/></div>

)

但是,当我在 aspx 页面中复制结果和硬编码时,它可以正常工作,但不能通过 ajax。

这是我取得成功的原因:

 <div class='col-sm-4'>
                   <div class='pie-chart1 pie-chart pie-number easyPieChart' data-percent=33% style='width: 220px; height: 220px; line-height: 220px;'>33% <canvas width='220' height ='220'/></div>

               </div>
                <div  class='rankadvancement'>
                    <div class='row-fluid'>
                        <span class='span2'>
                            <div class='percent'>33%</div>

                        </span>
                        <span class='span10'>
                            <a href='javascript:loadRankAdvancement(6);' class='next'><img src='Assets/Images/btnArrowRight.png' /></a>
                            <a href='javascript:loadRankAdvancement(4);' class='previous'><img src='Assets/Images/btnArrowLeft.png' /></a>
                            <h3>Pearl Ambassador</h3>
                            <div class='progress progress-magenta'>
                                <div class='bar' style='width: 33%'></div>

                            </div>

                        </span>

                    </div>
                    <div class='goals'>
                        <div class='clearfix'></div>

                    </div>

                </div>

尝试但不工作:我可以看到隐藏变量中的值,但实际上在网页上看不到结果:

<!///<input name="ctl00$Content$piechartval" type="hien" id="Content_piechartval" class="piechartval" value=" <div class='col-sm-4'><div class='pie-chart1 pie-chart pie-number easyPieChart' data-percent=33% style='width: 220px; height: 220px; line-height: 220px;'>33% <canvas width='220' height ='220'/></div></div><div  class='rankadvancement' <img src='Assets/Images/imgLoading.gif' style='width: 16px;'><div class='row-fluid'><span class='span2'><div class='percent'>33%</div></span><span class='span10'><a href='javascript:loadRankAdvancement(6);' class='next'><img src='Assets/Images/btnArrowRight.png' /></a><a href='javascript:loadRankAdvancement(4);' class='previous'><img src='Assets/Images/btnArrowLeft.png' /></a><h3>Pearl Ambassador</h3><div class='progress progress-magenta'><div class='bar' style='width: 33%'></div></div></span></div><div class='goals'><div class='clearfix'></div></div></div>"
4

3 回答 3

0

据我所知,您只需要更新输入值属性

<input type="hidden" runat="server" ID="piechartval" value="HERE" />

success: function(data) {

     $('input#piechartval').attr(value,data); --- this one in hidden input
     $('.rankadvancement').html(data); --- this one in div
}
于 2013-09-05T17:42:04.067 回答
0

我建议您不要在服务器响应中使用标记,而是坚持使用 JSON。我的疯狂猜测是你正在用错误的标记抓住inputordiv标记。如果你返回 JSON,那么它就很简单。

success: function (data) {
  $('#piechartval').val(data.val);
  $('.rankadvancement').text(data.val);
}
于 2013-09-05T17:38:33.383 回答
-1

试试这段代码,看看会发生什么:

<input type="hidden" runat="server" class="piechartval" ID="piechartval" value="HERE" />
   <div class="rankadvancement "><img src="Assets/Images/imgLoading.gif" style="width: 16px;" />HERE<div>



 success: function(data) {

     $('.piechartval').val(data); --- this one in hidden input
     $('.rankadvancement').html(data); --- this one in div
}

编辑:附带说明,在隐藏的 div 上使用一个类,因为 ID 会因为runat="server". 修复了代码以反映这一点。

于 2013-09-05T17:28:45.783 回答