Ajax数据发布

Hello im trying to implement an ajax invitation script which will let the user to invite his/her friends to that event. I use the mostly same javascript in the other parts of the website and they work perfect, but in this case, it doesn't work, i'm sure that the problem persists because of the javascript part, because as i said, i use the nearly exact script and it works perfect, when i post the data, it doesn't send the email, my mail function works good ( in other pages i use the same without ajax and it works ) but i think the javascript part can't post the data in this case.

By the way there is not any problem with getting the values in the hidden parts.

Hope you can help.

the javascript part :

 <script type=\"text/javascript\">
 $(document).ready(function() {

$('.error').hide(); //Hide error messages 
$('#MainResult').hide(); //we will hide this right now

$(\"#button\").click(function() { //User clicks on Submit button


 var js_name = $(\"#name\").val();
 var js_message = $(\"#message\").val();
 var js_username = $(\"#username\").val();
 var js_useremail = $(\"#useremail\").val();
 var js_eventname = $(\"#eventname\").val();

 if(js_name==\"\"){
     $(\"#nameLb .error\").show(); // If Field is empty, we'll just show error text inside <span> tag.
     return false;}
if( js_message==\"\"){
     $(\"#messageLb .error\").show(); // If Field is empty, we'll just show error text inside <span> tag.
     return false;}


  var myData = 'postName='+ js_name + '&postMessage=' + js_message + '&username=' + js_username  + '&useremail=' + js_useremail  + '&eventname=' + js_eventname;

        jQuery.ajax({
            type: \"POST\",
            url: \"invite.php\",
            dataType:\"html\",
            data:myData,
            success:function(response){
                $(\"#MainResult\").html('<fieldset class=\"response\">'+response+'</fieldset>');
                $(\"#MainResult\").slideDown(\"slow\"); //show Result 
                $(\"#MainContent\").hide(); //hide form div slowly
            },
            error:function (xhr, ajaxOptions, thrownError){
                $(\"#ErrResults\").html(thrownError);
            }    
        });
    return false;
});


$(\"#gobacknow\").live(\"click\", function() { 
            $(\"#MainResult\").hide(); //show Result 
            $(\"#MainContent\").slideDown(\"slow\"); //hide form div slowly

            //clear all fields to empty state
            $(\"#name\").val('');$(\"#message\").val('');
});

$(\"#OpenContact\").live(\"click\", function() { 
            $(\"#form-wapper\").toggle(\"slow\");

});
 });
 </script>

the html part:

  <div id="form-wapper">
    <div id="form-inner">
    <div id="ErrResults"><!-- retrive Error Here --></div>
    <div id="MainResult"><!-- retrive response Here --></div>
    <div id="MainContent">
    <fieldset>
        <form id="MyContactForm" name="MyContactForm" method="post" action="">
        <label for="name" id="nameLb">Email : <span class="error" style="font-size:10px; color:red;">Error.</span></label>
        <input type="text" name="name" id="name" />
        <label for="message" name="messageLb" id="messageLb">Message : <span class="error" style="font-size:10px; color:red;">Error.</span></label><textarea style="resize:vertical;" name="message" id="message" ></textarea>
        <input type="hidden" name="username" id="username" value="<?php echo get_username($userid); ?>">
        <input type="hidden" name="useremail" id="useremail" value="<?php echo get_email($userid); ?>">
        <input type="hidden" name="eventname" id="eventname" value="<?php echo $eventname; ?>">
      <br><button id="button">Send</button>

        </form>
    </fieldset>
    </div>
    <div style="clear:both;"></div>
</div>

invite php file :

$postName       =  filter_var($_POST["postName"], FILTER_SANITIZE_STRING); 
$postMessage    = filter_var($_POST["postMessage"], FILTER_SANITIZE_STRING);
$username = filter_var($_POST["username"], FILTER_SANITIZE_STRING);
$useremail = filter_var($_POST["useremail"], FILTER_SANITIZE_STRING); 
$eventname= filter_var($_POST["eventname"], FILTER_SANITIZE_STRING);
invite($useremail, $postMessage , $username, $eventname, $postName); // this is a functipon that i use, it works in other cases, but not working in here

Rather than trying to debug that javascript, here is a much much easier / cleaner way to do this for the javascript AJAX post:

$.post('invite.php',$('#MyContactForm').serialize(),function(data){
    if(data.success){
      // all your on success stuff here
        alert('success!');
    }else{
      // show error messages
        alert(data.e);
    }
},'json');

For your PHP part, echo a JSON response array, eg:

$data['success']=false;
$data['e']='Some error';
echo json_encode($data);