Success and Failure message after ajax call in php

when user submit form or update data in database table using jquery ajax call then success and failure notification message show on the popup alert to the user.

if action is successfully perform then ajax show success message using sweet alert. other wise it show failure message .

Example

File Name :

<form id="frm">
<div class="input-group">
<input class="btn btn-lg" name="email" id="email" type="email" placeholder="Enter Your Email" required/>
<button type="submit" class="button">Submit</button>
</div>
</form>

<!-- success message rendered inside this result div -->
<div id="result"></div>

<div class="text-center">
<span id="success" class="text-success"></span>
<span id="wanings" class="text-danger"></span>
</div>

</div>
</div>
<br/>

<p class="title"><b> script </b></p>
<div class="ittutorial-example">
<p>File Name : </p>
<div class="ittutorial-code">

<script>
$(document).ready(function(){
$('#frm').submit(function(event){
event.preventDefault();

/*
var $form = $(this),
var title = $('#title').val();
var body = $('#body').val();
var url = $form.attr('action');
var method = $form.attr('method');
*/

var email = $('#email').val();

if(email == ''){
$('#warnings').html('All Fields are Required');
}else{
$('#warnings').html('');
$.ajax({
url: "action_process.php"
method:'POST',
data:{email: email},
success:function(data){
$('#frm').trigger('reset');
$('#success').fadeIn().html(data);
setTimeout(function function_name() {
$('#success').fadeOut('slow');
}, 3000);

}
});

}

});
});
</script>

Show sweet alert message success or failure.

<script type="text/javascript">

$(document).ready(function() {
// $('#tech_committees').on('change', function() {
$('#tech_committees').change(function() {
var tech_committees_id = this.value;

if((tech_committees_id == null || tech_committees_id == '' || tech_committees_id=== undefined))
{
alert("Please Select");

}
else{

$.ajax({

url:"<?php echo base_url();?>ittutorial/new_tutorial",
data:{tech_id:tech_id},
method:"post",
dataType:"Json",
success:function(data){

if(data.status == '0')
{
// $('#myDiv').html(data.msg);
swal("Error!", "You have already filled data", "error");
$('#new_dataajax').hide();
setTimeout(function(){
location.reload(true);
},1000);
}
else{
$('#newaction_data').hide();
$('#new_dataajax').html(data);
}


},
/*error:function(){
alert("Error occured");
}*/
});
}

});

});
</script>


public function new_action_plan() {
$tech_id=$this->input->post('tech_id');
....................
....................
....................
$data_msg = array(
'msg'=>'You have already filled data of this technical committees of financial year',
'status'=>'0'
);

echo json_encode($data_msg);

exit;
}





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here