Update status to approved via AJAX when clicking a button - php

How can I update a 'status' field as approved when I click on a button?
function UpdateRecord(id) {
jQuery.ajax({
type: "POST",
url: "update.php",
data: 'id=' + id,
cache: false,
success: function(response) {
alert("Record successfully updated");
}
});
}

<script>
function UpdateRecord(id)
{
jQuery.ajax({
type: "POST",
url: "update.php",
data: {id:id},
cache: false,
success: function(response)
{
alert("Record successfully updated");
}
});
}
</script>
and in update.php
<?php
if(isset($_POST['id']))
{
$id = $_POST['id'];
// update here to this id..
}
?>

Related

How to retrieve textbox value in a controller which is supplied with ajax?

I want to pass value of text box to my controller, i can pass that but i cant retrieve it at controller. Help me to identify my mistake.
Form.php (dept_name is a id of my textbox)
<script>
$(document).ready(function() {
$("#submitbutton").click(function(e) {
var deptname=$('#dept_name').val();
$.ajax({
url: 'http://localhost/finalProjectWork/admin_department_controller/adddept/',
type: 'POST',
method: 'POST',
headers: {'Cache-Control': 'no-cache'},
data: {name:deptname},
contentType: false,
processData: false,
success: function(test) {
alert(test);
},
error: function() {
alert("Already Exists");
}
});
e.preventDefault();
});
});</script>
controller :
public function adddept()
{
$deptname=$this->input->post('name');
$this->load->model('admin_department_model');
$this->admin_department_model->insertdept($deptname);
echo "Successfully inserted";
}
Try this
<script>
$(document).ready(function() {
$("#submitbutton").click(function(e) {
var deptname=$('#dept_name').val();
$.ajax({
url: 'http://localhost/finalProjectWork/admin_department_controller/adddept/',
type: 'POST',
method: 'POST',
headers: {'Cache-Control': 'no-cache'},
data: {name:deptname},
success: function(test) {
alert(test);
},
error: function() {
alert("Already Exists");
}
});
e.preventDefault();
});
});</script>

Pagin With Ajax, Post no working

I Use this code for paging
function changePagination(pageId,liId,modul,userid){
$(".flash").show();
var dataModul = 'modul='+modul;
var dataUser = 'userid='+userid;
var dataString = 'pageId='+ pageId;
$.ajax({
type: "POST",
url: "loadDataVerifikasi.php",
data: dataString,
data: dataModul,
data: dataUser,
cache: false,
success: function(result){
$(".flash").hide();
$(".link a").removeClass("In-active current") ;
$("#"+liId+" a").addClass( "In-active current" );
$("#pageData").html(result);
}
});}
And this for an action file with name loadDataVerifikasi.php
if(isset($_POST['pageId']) && !empty($_POST['pageId'])){
$id=$_POST['pageId'];
}
else{
$id='0';
}
$pageLimit=PAGE_PER_NO*$id;
$query="select * from pengajuan_".$_POST['modul']." join verifikasi on pengajuan_".$_POST['modul'].".ketkdpengajuan = verifikasi.ketkdpengajuan where kdadmin = '".$_POST['userid']."' group by kdverifikasi limit $pageLimit,".PAGE_PER_NO;
But $_POST['modul'] post nothing,
I am not familiar with your syntax.
Please try:
function changePagination(pageId,liId,modul,userid){
$(".flash").show();
var datastring = {
modul: modul,
userid: userid,
pageId: pageId
}
$.ajax({
type: "POST",
url: "loadDataVerifikasi.php",
data: dataString,
cache: false,
success: function(result){
$(".flash").hide();
$(".link a").removeClass("In-active current") ;
$("#"+liId+" a").addClass( "In-active current" );
$("#pageData").html(result);
}
});
}
The $.ajax data attribute accepts an object with key-value pairs
I believe it is because you overwrite the data with dataUser.
I haven't tested i but the code below should work.
Also check out this for more info
function changePagination(pageId,liId,modul,userid){
$(".flash").show();
var dataModul = 'modul='+modul;
var dataUser = 'userid='+userid;
var dataString = 'pageId='+ pageId;
$.ajax({
type: "POST",
url: "loadDataVerifikasi.php",
data: { 'dataString':dataString, 'dataModul':dataModul, 'dataUser':dataUser },
cache: false,
success: function(result){
$(".flash").hide();
$(".link a").removeClass("In-active current") ;
$("#"+liId+" a").addClass( "In-active current" );
$("#pageData").html(result);

How redirect page without refreshing main page after ajax success function

After ajax success function, I want to redirect page to comment.php without refreshing main page
$.ajax({
type: "POST",
url: "save_edit.php",
data: { id1: id, comment1: comment },
success: function(data) {
$("#feedback").html(data);
$('#feedback').fadeIn('slow', function() {
$('#feedback').fadeOut(4000);
window.location = "comment.php";
}
});
$.ajax ({
type: "POST",
url: "save_edit.php",
data: { id1: id, comment1: comment },
success: function(data) {
$("#feedback").html(data);
$('#feedback').fadeIn('slow', function() {
$('#feedback').fadeOut(4000);
$.ajax ({
type: "POST",
url: "comment.php",
data: { },
});
}
});
You can not redirect to a page without refreshing. You need to load page into your current page like this;
$.ajax ({
type: "POST",
url: "save_edit.php",
data: { id1: id, comment1: comment },
success: function(data) {
$("#feedback").html(data);
$('#feedback').fadeIn('slow', function() {
$('#feedback').fadeOut(4000);
$("body").load("comment.php");
}
});
comment.php should only contain body part
Use like this:
$.ajax ({
type: "POST",
url: "save_edit.php",
data: { id1: id, comment1: comment },
success: function(data) {
$("#feedback").html(data);
$('#feedback').fadeIn('slow', function() {
$('#feedback').fadeOut(4000);
$.ajax ({
type: "POST",
url: "save_edit.php",
});
}
});
On success event use
window.location.href="your page link";

Get a variable after ajax when done

$('#submit_id').click(function(){
function mark() {
$.ajax({
type: "POST",
url: "request1.php",
data: $('#form_id').serialize(),
cache: false,
success: function(data1){
}
});
}
function other() {
$.ajax({
type: "POST",
url: "request2.php",
data: $('#form_id').serialize(),
cache: false,
success: function(data2){
}
});
}
$.when(mark(), other()).done(function(data1, data2)
{
console.log(data1);
$(".results1").html(data1);
console.log(data2); // Result
$(".results2").html(data2);
});
});
I need to pass the returned data into a variable like:
console: undefined
You have to return promise interface from your functions as:
function mark() {
return $.ajax({
type: "POST",
url: "request1.php",
data: $('#form_id').serialize(),
cache: false
});
}
And you don't need to specify success callback here (but you still could).
Your code should work like this:
$.when(mark(), other()).done(function(data1, data2){
console.log(data1);
$(".results1").html(data1);
console.log(data2); // Result
$(".results2").html(data2);
});
function mark() {
return $.ajax({
type: "POST",
url: "request1.php",
data: $('#form_id').serialize(),
cache: false
});
}
function other() {
return $.ajax({
type: "POST",
url: "request2.php",
data: $('#form_id').serialize(),
cache: false
});
}
Try this
$('#submit_id').click(function(){
function mark() {
var res = null;
$.ajax({
type: "POST",
url: "request1.php",
data: $('#form_id').serialize(),
cache: false,
success: function(data1){
res= data1;
}
});
return res;
}
function other() {
var res = null;
$.ajax({
type: "POST",
url: "request2.php",
data: $('#form_id').serialize(),
cache: false,
success: function(data2){
res= data2;
}
});
return res;
}
$.when(mark(), other()).done(function(data1, data2)
{
console.log(data1);
$(".results1").html(data1);
console.log(data2); // Result
$(".results2").html(data2);
});
});

make jQuery post more than one query

i have a jQuery code that posts an ID to another php file
<script type="text/javascript">
$(function() {
//More Button
$('.more').live("click",function() {
var ID = $(this).attr("id");
if(ID){
$("#more"+ID).html('<img src="moreajax.gif" />');
$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("ol#updates").append(html);
$("#more"+ID).remove();
}
});
}else{
$(".morebox").html('The End');
}
return false;
});
});
</script>
How can I make it post another query along with "last message id"? I have a MySQL query that will output a value (pid). How can I post this along with "last message id"?
$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg="+ ID + "&pid=" + your_pid,
cache: false,
success: function(html){
$("ol#updates").append(html);
$("#more"+ID).remove();
}
});
Here is my solution:
var salji = {
rate: score,
image_id: img_id
};
$.ajax({
type: "POST",
url: "widgets/rate.php",
data: salji,
success: function(msg){
alert('wow');
}
});

Categories