使用ajax / jquery进行FORM检查

                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,   or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making   this question more broadly applicable, <a href="/help/reopen-questions">visit the help center</a>.

                    </div>
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2013-01-18 01:40:36Z" class="relativetime">7 years ago</span>.</div>
        </div>
    </aside>

im trying to send form with ajax and jquery to get result on same page. I have this code,that im linking from my form action :

function check()
{

    var html = $.ajax({
        type: "POST",
        url: "reg.php",
        data: $("#reg").serialize(),
        async: false
        }).responseText;
    if(html == "success") { 


        //Indicate a Successful Captcha
        $("#captcha-status").html("<p class=\"green bold\">Success! Thanks you may now proceed.</p>");
    } else {
        $("#captcha-status").html("<p class=\"red bold\">The security code you entered did not match. Please try again.</p>");

    }
}    

And then i have this rip of my php file :

$query = "SELECT * FROM teemo1 WHERE nick='$nick' and server='$server'";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) )
{
    echo 'success';
}
else
{
$queryy =  

     echo 'fail';
}

 }

I need to show in my page with form "Data successfully saved" and if fail "Incorrecta data", but i dont know how to get those echos from php file to my ajax script.

Thanks

</div>

try this :

function check(){
    $.ajax({
    type: "POST",
    url: "reg.php",
    data: $("#reg").serialize(),
    async: false,
    success:function(html){
        if(html == "success") { 
            $("#captcha-status").html("<p class=\"green bold\">Success! Thanks you may now proceed.</p>");
        } else {
            $("#captcha-status").html("<p class=\"red bold\">The security code you entered did not match. Please try again.</p>");
            }
        }
    });
}   

You need to use success function and use the passed value of success function parameter, which is responseText in your case.

$.ajax({
    type: "POST",
    url: "reg.php",
    data: $("#reg").serialize(),
    async: false
}).success(function(responseText){        
     if(responseText == "success") {       
      $("#captcha-status").html("<p class=\"green bold\">Success! Thanks you may now proceed.</p>");
     } else {
         $("#captcha-status").html("<p class=\"red bold\">The security code you entered did not match. Please try again.</p>");

     }
});