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.

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

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题