开发者

jQuery .html() help

开发者 https://www.devze.com 2023-02-19 09:41 出处:网络
I am doing the following: <script type=\"text/javascript\"> $(function(){ $(\"#ipad\").submit(function() {

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 l开发者_如何学运维ine $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.\n\n";
    txt+="Error description: " + err.description + "\n\n";
    txt+="Click OK to continue.\n\n";
    alert(txt);
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消