Click here to Skip to main content
16,020,186 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I want to submit form with ajax request but its not working !! I cant see any error but its not working my code is here


JavaScript
$(document).ready(function() {
 
$("#btn").click(function(){

	var name = $("#inputname").val();	

	var email = $("#inputEmail").val();
	
	var feed = $("#feedback").val();
	var send = "InputName=" + name + "&InputEmail=" + email + "&Feedback=" + feed ; 	
	alert(send); 
	$.ajax({
		url:"Feedback_conx.php",
		type:"POST",
		data:send,
		success: function(data1){
		$("#disp").html(data1);	
		}
		
	})
	
		});
	

			});


and php file is

PHP
 <?php

include_once("db_conx.php");
$name = $_POST['InputName'];
$email = $_POST['InputEmail'];
$feedback = $_POST['Feedback'];

if($name && $email && $feedback !=""){
	$sql = "INSERT INTO feedback(Name,Email,Feedback)VALUES('$name','$email','$feedback')";	
	$query = mysqli_query($con,$sql);
		echo "<div class='alert alert-dismissable alert-success'>
    Thank you for giving your valueable feedback to us!
	
</div>";
}
else 
{
echo "<div class='alert alert-dismissable alert-danger'>
    Please enter the all form details
</div>";

	
}
 ?>


html file

HTML
     <div class="row">
<form class="form-horizontal col-lg-5" id="frmfeed" name="frmfeed">
  <fieldset>
    <legend>Feedback </legend>
    <div class="form-group">
      <label for="inputEmail" class="col-lg-2 control-label">Name</label>
      <div class="col-lg-10">
        <input class="form-control" id="inputname" name="InputName" placeholder="Name" type="text">
      </div>
    </div>
    <div class="form-group">
      <label for="inputEmail" class="col-lg-2 control-label">Email</label>
      <div class="col-lg-10">
        <input class="form-control" id="inputEmail" name="InputEmail" placeholder="Email" type="text">
        </div>
    </div>
    <div class="form-group">
      <label for="feedback" class="col-lg-2 control-label">Feedback</label>
      <div class="col-lg-10">
        <textarea class="form-control" rows="3" id="feedback" name="Feedback"></textarea>
       
      </div>
    </div>
        <div class="form-group">
      <div class="col-lg-10 col-lg-offset-2">
        <button class="btn btn-default" type="reset" name="cancelbtn" id="cancelbtn">Cancel</button>
        <button type="submit" class="btn btn-primary" name="btn" id="btn">Submit</button>
      </div>
    </div>
  </fieldset>
</form>
<div id="disp" class="col-lg-5">



</div>

</div>
Posted
Updated 11-May-14 19:49pm
v2

Please try is as below.

$(document).ready(function() {
 
$("#btn").off('click').on('click', function(){
 
	var name = $("#inputname").val();	
 
	var email = $("#inputEmail").val();
	
	var feed = $("#feedback").val();
	var send = "InputName=" + name + "&InputEmail=" + email + "&Feedback=" + feed ; 	
	alert(send); 
	$.ajax({
		url:"/Feedback_conx.php",
		type:"POST",
		data:send,
		success: function(data1){
		$("#disp").html(data1);	
		}
		
	})
	
		});
	
 
			});
 
Share this answer
 
Comments
Md Jamaluddin Saiyed 12-May-14 1:46am    
I have tried but its not working ! my html code is here <div class="row">
<form class="form-horizontal col-lg-5" id="frmfeed" name="frmfeed">
<fieldset>
Feedback
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input class="form-control" id="inputname" name="InputName" placeholder="Name" type="text">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input class="form-control" id="inputEmail" name="InputEmail" placeholder="Email" type="text">
</div>
</div>
<div class="form-group">
<label for="feedback" class="col-lg-2 control-label">Feedback</label>
<div class="col-lg-10">
<textarea class="form-control" rows="3" id="feedback" name="Feedback"></textarea>

</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default" type="reset" name="cancelbtn" id="cancelbtn">Cancel</button>
<button type="submit" class="btn btn-primary" name="btn" id="btn">Submit</button>
</div>
</div>
</fieldset>
</form>
<div id="disp" class="col-lg-5">



</div>

</div>
Sampath Lokuge 12-May-14 2:34am    
Have you put a debug and checked ? Where is the issue ? Is that not firing the event or run time issue or what ?
Just check request is reaching in the server using FireFox FireBug tool or Google Chrome Developer tool.

If it going just do response clear and set content type to HTML, in the PHP Server code
 
Share this answer
 
Did you try catching error to check for any failures?
 
Share this answer
 
Comments
Md Jamaluddin Saiyed 12-May-14 2:29am    
no
ArunRajendra 12-May-14 2:32am    
Catch error. I guess there is some error which occurring but getting reported.
Md Jamaluddin Saiyed 12-May-14 2:32am    
how to check
ArunRajendra 12-May-14 2:44am    
Add this code to your ajax call similar to what you have done for success.

error: function (xhr) {
alert(xhr.responseText);
}
Md Jamaluddin Saiyed 12-May-14 2:53am    
i have done it but i cant see msg !! its disappeared immediately

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900