Arne-Kolja Bachstein schrieb:
> Hi there
>
> first a great hello to all the people discussing here, I am the new one
> :-) New at both this list and jQuery itself. So here is my first
> question, I hope you can help me with this.
>
> I am trying to create a rudimentary contact form and am using this code
> at the moment:
>
> $('form#contactForm').submit(function(){
> $.post('contact.send.php','',function(txt) {
>
> $("table#kontaktformular").before("<div
> class=\"returnMessage\">"+txt+"</div>");
> return false;
> });
> });
>
> This seems to work... but only sometimes. I don't know if it's the
> browser not waiting long enough for the return message that gives me the
> txt variable... but it must be something like that. If I submit the
> corresponding form and the php script reacts immediatly (error message
> regarding missing entries), it sometimes (! *lol*) displays the
> returnMessage, but if an email is about to be sent, it doesn't. Well, it
> even seems to cancel the php script! If I call the php script without
> jQuery by implementing it "as usual" the script works perfectly.
>
> Any ideas about this? Or do I really _have_ to use a plugin for this? In
> my case actually the .post() function with callback should be enough...
> I thought.
Welcome Arne!
I think you have to move the "return false" out of the callback function
to switch off the forms default action. The way it is now both form
submission and $.post would interfere.
$('#contactForm').submit(function(){
$.post('contact.send.php','',function(txt) {
$("#kontaktformular").before("<div
class=\"returnMessage\">"+txt+"</div>");
});
return false;
});
Another hint: removing the element from your selector should result in
better performance, because jQuery doesn't have to look for all elements
of a type before checking for the id:
$('#contactForm')
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/