jQuery Ajax - Sending form data
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
PloMar
- Posts: 48
jQuery Ajax - Sending form data
Hello
I have the following code to send form data to a php script, with jQuery Ajax, withouut reloading the page.
But, when I press the Submit button it opens the "page.php", and the alert() isn't displayed.
Code: Select all
<script>
$(document).ready(function(){
$('#form').submit(function(e) {
var form_data = $(this).serialize();
$.ajax({
type: 'POST',
url: '/page.php',
data: form_data,
success: function() {
alert('Message sent');
}
});
});
});
</script>
- How to make it work?
Admin
Hi,
You have to call preventDefault() method to stop default action.
Code: Select all
<script>
$(document).ready(function(){
$('#form').submit(function(e) {
e.preventDefault(); // STOP default action
e.unbind(); // unbind. to stop multiple form submit
var form_data = $(this).serialize(); // get form data into a string with pairs: name=value
$.ajax({
type: 'POST',
url: '/page.php',
data: form_data,
success: function() {
alert('Message sent');
}
});
});
});
</script>
Similar Topics
-
mysql not insert data from form
PHP - MySQL
First post
i have two php files:
the index.php ---
<?php
$id = 3 ;
if(!empty($_POST )) {
$conn = mysql_connect( localhost , website_rent , password...
Last post
I not know way it not works; maybe data from the resulted sql query is not ok for that mysql table structure.
If there is no message with errors,...
-
Alert on jquery ajax requst when new response
JavaScript - jQuery - Ajax
First post
I have a jquery ajax function that is called every second, with setTimeout().
I want an alert to pop up whenever a new message is received.
Here's...
Last post
Try something like this, store the previous response into a variable, and alert the message if response changed:
var msg_res =''; //store the...
-
jQuery Hide and Show effect with data from php
JavaScript - jQuery - Ajax
First post
Dear Admin I would love to use this script, but their is a problem with the first record in my sql-table (DESC)
The first record (DESC) is not...
Last post
The php, javascript and html codes are wrong mixed.
It is good to avoid mixing javascript code in php strings.
- Try this:
<?php
//your...
-
3 clickable icons in form
HTML - CSS
First post
I want to moderate my textboxes with icons
for this i have this script but i can`t place 3 icons
meight you could support me... how to do...
Last post
I found an answer to work with classes
-
Select in mysql table with password from form not work
PHP - MySQL
First post
hello,
i have a problem with this code:
if(isset($_POST ))
{
$txt_login= mysqli_real_escape_string($con,$_POST );
$txt_pass=...
Last post
thank you for your help.
i can find this problem!
it was a space line in user_password=' $hashed_password' in register code.
all of the passwords...