Why won't the simple javascript search() function not work on ajax delivered output?
<p>The output I am getting is this html:</p>

<pre><code>&lt;form action="?next=/pm/write/" method="post"&gt;

    &lt;label&gt;Recipient:&lt;/label&gt;
    &lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;
    &lt;input type="text" name="recipients" id="id_recipients" /&gt;

    &lt;br /&gt;

    &lt;label&gt;Subject:&lt;/label&gt;
    &lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;
    &lt;input id="id_subject" type="text" name="subject" maxlength="120" /&gt;

    &lt;br /&gt;

    &lt;label&gt;Body:&lt;/label&gt;

    &lt;textarea id="id_body" rows="12" cols="55" name="body"&gt;&lt;/textarea&gt;

    &lt;input type="submit" value="Send" class="yes" /&gt;
    &lt;input type="reset" value="Clear" class="no" /&gt;
&lt;/form&gt;
</code></pre>

<p>Here's the Javascript:</p>

<pre><code>$('#ajaxForm input[type="submit"]').live('click', function(e) {
    $.ajax({
        url: '/pm/write/',
        type: 'post',
        data: $('#ajaxForm form').serialize(),
        success: function(output) {

            if (output.search('errorlist') != -1) {
                alert('error found');
            }
            else {
                alert('all good');
            }
        }
    });
    e.preventDefault();
});
</code></pre>

<p>As you can see the output does contain the string "errorlist" and the error I get is "error found". That's good but the problem is I always get this alert even when the output does not contain that "errorlist" string, how to fix this?</p>

<h2>UPDATE</h2>

<p>Here's what the output looks like when there are no errors:</p>

<pre><code>&lt;form action="" method="post"&gt;

    &lt;label&gt;Recipient:&lt;/label&gt;

    &lt;input type="text" name="recipients" id="id_recipients" /&gt;

    &lt;br /&gt;

    &lt;label&gt;Subject:&lt;/label&gt;


    &lt;input id="id_subject" type="text" name="subject" maxlength="120" /&gt;

    &lt;br /&gt;

    &lt;label&gt;Body:&lt;/label&gt;

    &lt;textarea id="id_body" rows="12" cols="55" name="body"&gt;&lt;/textarea&gt;

    &lt;input type="submit" value="Send" class="yes" /&gt;
    &lt;input type="reset" value="Clear" class="no" /&gt;

&lt;/form&gt;
</code></pre>
