duanchuang1935 2011-03-25 01:05
浏览 32
已采纳

jQuery .html()帮助

I am doing the following:

<script type="text/javascript">
$(function(){
    $("#ipad").submit(function() {
    $.post("ipadcheck.php", $("#ipad").serialize(),
    function(data) 
    {
        if(data.error == 'TRUE') 
        {   
             $("#results_ajax").html("<div class='AppleRed'>Sorry There were Errors: " + data.error_message + "</div>");
        }
        else
        {
            $("#results_ajax").html("<div>"+ data.disp + "</div");
        }


    }, "json");

    return false;

});

});

When the user enters data into a form and submits the form gets submitted. I know that data.error == 'TRUE' gets hit because when I cause an error on purpose I get my error message.

I know that I am building up the results for data.disp as they are:

<div class='paragraph_style'><br />

<strong> San Jose College Park</strong>
<br/>2.33 miles<br />Out Of Stock
<strong> San Jose Westgate</strong>
<br/>3.35 miles<br />Out Of Stock

</div>

Using Firebug I see this come back, It looks good

But it does not get displayed.

I have been pulling my hair out for 3 hours!

UPDATE: Definitely a problem with my string, an encoding issue. I replaced my string with the work "Hello" and it works. Why did I not think of such a simple test sooner...

UPDATE 2: I am using this:

$m=array();
preg_match_all('/<p>[\s\S]*?<strong>([\s\S]*?)<\/p>/i',$buffer,$m);

foreach($m[1] as $mnum=>$match) 
{ 
    $displayString .="<br /><strong>";
    $displayString .= $match;
    $displayString .="<br />";
}

It is this line $displayString .= $match; Maybe I don't know how to output the value of $m[1]? What happens here is $buffer is curl output and I find all instances of

and they go into $m. Any advice?

EDIT: I tried wrapping the jquery .html() in a try/catch and nothing happens, I never hit it or get the alert.

try
{
    $("#results_ajax").html("<div>"+ data.disp + "</div>");
    alert($("#results_ajax").html());
}
catch(err)
{
    txt="There was an error on this page.

";
    txt+="Error description: " + err.description + "

";
    txt+="Click OK to continue.

";
    alert(txt);
}
  • 写回答

1条回答 默认 最新

  • dongmeng4742 2011-03-25 01:56
    关注

    Right after your $("#results_ajax").html("<div>"+ data.disp + "</div>"); call, do an alert($("#results_ajax").html()); to see the html that actually got inserted.

    It is possible it is the newlines you have embedded in the string. Try generating the same string without the newlines to see if that is where the problem lies.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图