根据用户输入表单错误处理ajax

Couldn't find any valueable answers on this question: Its a pretty basic ajax form process handler:

$(document).ready(function(){

});
function functionToUpdate(id)
{
    var data = $('form').serialize();
    $('form').unbind('submit');                
    $.ajax({
        url: "Blahblah.php",
        type: 'POST',
        data: data,
        dataType:"json",
        beforeSend: function() {

        },
        success: function(msg) 
        {
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(req.responseText);      
        }
    });
    return false;
} 

Works fine to update stuff in the mysql database. (This is a php file) I check in the php file the values , with different checks as isset($Post) etc.

So for example:

if(isset($_POST['submit']))
{
    //do stuff here if button is clicked
}
else{
    // play a nice error message
}

How to get this info from the url displayed in the ajax's succes part? something like this: (For example)

success: function(msg) 
{
   if(post = true)
   {
       $('#succesfull').html("Succesfull query").fadeIn(800)
   }
   else
   {
       $('#fault').html("U didn't fill stuff in, failed!").fadeIn(800)
   }
},

For example this upset. But i just can't get this data from the focused url.

all help is appriciated.

You need to process the output of Blahblah.php retuned as msg.

success: function(msg) 
        {
           if(msg=='xxxx'){
             //Do stuff
           }
        },

Edit:

I think you may have misunderstood the meaning of success: in the ajax call. This is indicating the called page loaded successfully.

Take a look at .ajax. For this case it may be simpler to use $.post

or even $.getJSON

If you use JSON the output of Blahblah.php must be json_encode.

Edit:

To return the html output of Blahblah.php try something like:

<?php
//must be before any output
ob_start();

//php code

$output = ob_get_contents();
$return['data'] = utf8_encode($output);
ob_end_clean();
echo json_encode($return);
?>

Then in jQuery

$.post("Blahblah.php", data, function(msg)
{
  $('#succesfull').html(msg.data);
}, "json");