How to submit a form to php script using ajax

I have a form that is a
chat apps am building
for project. Now
everything seems to be
working fine to best of
my ability.
Now i want to submit
the data from the form
into my php script
without any form of
reload. That means i
don’t want redirection
to the action page and
back to the chat page.
What i want is for the
page to submit the
form at the background.
And i know i need ajax
to this bt i cnt get it
right. Here is my form

<form method="post" id='chatbox' action="reply.php"> <input type="text" id="text" name="adchat"/> <input type='hidden' id='user_id' name='id' value='1'> <input type='hidden' id='user_name' name='id' value='Ben'> <input type='submit' id='submit' name='chat' value='send'></form>

What i need is an ajax
code to submit d
variable to the reply.php
scrit and maybe a
message to display
when the form it been
submitted say
something like
(sending…). Thanks for
assiting. Am sorry that i did not paste Ajax code that is because i don’t know it so please forgive me. Donot bother about the view of the input. Thanks once again

I’ll help yeh out.

[code]

[/code]

You should use the same values for “id” and “name” because things can get confusing. You need the id for selecting in JQuery and name for $_POST in PHP.

Notice I’ve changed the submit input type from “submit” to “button” - JQuery is submitting the form, so using type=“submit” would submit the form twice, two different ways.

Look at line 5: “reply.php”, - replace that file path with the path to your MySQL script that will receive the values posted from this page.

Line 7-9:

//function(data) { // $('#show_results').html(data) //}
I commented this code because I’m not sure you want/need it. It sounds like you just want the form to save, but you can add feedback or whatever you want. All you need to do is write HTML in your “reply.php” like: Form submitted after a successful query - put

in this current page’s code and when you submit the form, the span will appear inside the show_results div. The possibilities are pretty endless if you can imagine what you could do.

If you need help with the MySQL, let me know.

thanks man trying out vry soon. My system is bad

Sponsor our Newsletter | Privacy Policy | Terms of Service