tags:

views:

184

answers:

2

Currently, I have this line:

$.post("submitmail.php", $("#contactform").serialize(), recvMailStatus);

I'm new to jQuery so this may be an absurdly stupid question.
But I'm making this project work with or without javascript, so if a form is submitted with this function, I want submitmail.php to just echo whether or not it was successful. If the form just submits and redirects to submitmail.php, I want it to display something other than a white screen with black text saying "mail sent successfully." To do this I figured I would just post an extra variable "fromjs" or something so that the page can render itself accordingly. What's the best way to do that?

+2  A: 

You may append it to the address you are posting to:

$.post(
    "submitmail.php?formjs=some_value", 
    $("#contactform").serialize(), 
    recvMailStatus
);

or:

$.post(
    "submitmail.php", 
    $("#contactform").serialize() + '&formjs=some_value', 
    recvMailStatus
);
Darin Dimitrov
perfect, I'm using the second example
Carson Myers
+1  A: 

Hi,

The best way is to use $.ajax function, like this :

$.ajax({
   type: "POST",
   url: "submitmail.php",
   success: function(msg){
     alert(msg);
   }
 });

You can modify it in order to display other kind of window, JQuery has some pretty plugins about alert customization. Also, you need to catch the submittion of the form and avoid your page from being redirected.

yoda