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);
Related
This Script is not working on opencart 2.3.0.2 can any one help to translate this?
Is there a problem with user token?
<script type="text/javascript"><!--
function refudt(ele){
var pid = $(ele).data('pid');
var type= $(ele).data('type');
$.ajax({
url: 'index.php?route=sale/order/getprice&user_token=
{{ user_token }}',
dataType: 'html',
type: 'post',
data: 'order_id={{ order_id }}&pid=' + pid+'&type='+type,
success: function(html) {
$(ele).parent().append('<br>'+html);
}
});
}
function saver(ele){
var pid = $(ele).data('pid');
var price = $(ele).parent().find('input').val();
var type= $(ele).data('type');
confirm('Save new value: '+price +' ?');
$.ajax({
url: 'index.php?route=sale/order/getprice&user_token=
{{ user_token }}',
dataType: 'html',
type: 'post',
data: 'order_id={{ order_id }}&pid=' + pid+'&value='+price+'&type='+type,
success: function(html) {
$(ele).parent().remove();
if($('.rebus').length<1) {
location.reload();
}
}
});
}
//--></script>
you use twig function for OC2.3 version. This OC version does not suport twig. And instead user_token should be just token. Script you need change to:
<script type="text/javascript"><!--
function refudt(ele){
var pid = $(ele).data('pid');
var type= $(ele).data('type');
$.ajax({
url: 'index.php?route=sale/order/getprice&token=<?php echo $token; ?>,
dataType: 'html',
type: 'post',
data: 'order_id=<?php echo $order_id; ?>&pid=' + pid+'&type='+type,
success: function(html) {
$(ele).parent().append('<br>'+html);
}
});
}
function saver(ele){
var pid = $(ele).data('pid');
var price = $(ele).parent().find('input').val();
var type= $(ele).data('type');
confirm('Save new value: '+price +' ?');
$.ajax({
url: 'index.php?route=sale/order/getprice&token=<?php echo $token; ?>,
dataType: 'html',
type: 'post',
data: 'order_id=<?php echo $order_id; ?>&pid=' + pid+'&value='+price+'&type='+type,
success: function(html) {
$(ele).parent().remove();
if($('.rebus').length<1) {
location.reload();
}
}
});
}
//--></script>
Also do not forget that token should be defined on corresponding controller file like this: $data['token'] = $this->session->data['token'];
I have a function to call a PHP script using Ajax, I would to add another event to call the same PHP page, how can I add it instead of repeating the same Ajax call?
$('.episodeNum').change(function(){
var formItems = $('form.addMedia').serialize();
var dataString = formItems;
$.ajax({
type: "POST",
url: "grabMedia.php",
data: dataString,
dataType: "json",
success: function(data) {
I would to add a click function to call the same script:
$('.clickButton').click(function(){
var formItems = $('form.addMedia').serialize();
var dataString = formItems;
$.ajax({
type: "POST",
url: "grabMedia.php",
data: dataString,
dataType: "json",
success: function(data) {
How can I combine both of them??
Thanks for your usual help
A function of the code can be made and it can be called on both the events:
function post_data()
{
var formItems = $('form.addMedia').serialize();
var dataString = formItems;
$.ajax({
type: "POST",
url: "grabMedia.php",
data: dataString,
dataType: "json",
success: function(data) { }
}
$('.episodeNum').change(function(){
post_data();
});
$('.clickButton').click(function(){
post_data();
});
Does this suit your need?
var post_data = function()
{
var formItems = $('form.addMedia').serialize();
var dataString = formItems;
$.ajax({
type: "POST",
url: "grabMedia.php",
data: dataString,
dataType: "json",
success: function(data) { }
};
$('.episodeNum').change(post_data);
$('.clickButton').click(post_data);
I have code in my html file as below. I am using jQuery Mobile
$.ajax({
type: "GET",
url: "http://localhost/owner_pickup.php",
cache: false,
dataType:'json'
success: function(data)
{
// On success
}
});
owner_pickup.php returns me data by executing query. Now i need to pass a value which i would read in my owner_pickup.php file.
Kindly suggest me how would we pass the value
in your php file:
$value = array(
"dat_1" => "this is data number 1",
"dat_2" => "this is data number 2"
);
echo json_encode($value);
in your jquery finction:
$.ajax({
type: "GET",
url: "http://localhost/owner_pickup.php",
cache: false,
dataType:'json'
success: function(data)
{
var value1 = data.dat_1;
var value2 = data.dat_2;
}
});
please look at this answers:
retrieve multiple values from ajax call
if you don't know how to use JSON please google it.
edit:
pass a value to the php:
$.ajax({
type: "GET",
url: "http://localhost/owner_pickup.php",
cache: false,
data: {
first_value:50,
second_value:55
}
dataType:'json'
success: function(data)
{
var value1 = data.dat_1;
var value2 = data.dat_2;
}
});
in the php:
if(isset($_GET['first_value']))
$first = $_GET['first_value'];
$.ajax({
type: "GET",
url: "http://localhost/owner_pickup.php",
data: {param1: 123, param2: "text value"},
cache: false,
dataType:'json',
success: function(data) { // On success }
});
$.ajax({
type: "GET",
url: "http://localhost/owner_pickup.php",
data:{key1:value1}
cache: false,
dataType:'json'
success: function(data)
{
}
});
In php aaccept it as
<?php
$_REQUEST['key1'];
?>
I want to request ajax many time in for loop . But it only return 1 value . result.ID. Can anyone help me?
$('#show').html('');
var min = parseInt($('#number_coupon_from').val());
var max = parseInt($('#number_coupon_to').val());
var total_time = parseInt($('#time_coupon').val())*1000;
var randcoupon = Math.floor(Math.random()*(max-min+1)+min);
var timetb = total_time/randcoupon;
var random = 0;
var i,j;
for(i=0;i<randcoupon;i++)
{
for(j=random;j>=0;j--)
{
if(j==0)
{
$.ajax({
url: 'backend/publish_auto/update',
type: 'post',
data: {},
dataType: 'json',
success: function (result)
{
if(result.st)
{
$('#show').append('Update Coupon ID: '+result.ID+'<br />');
}
}
});
}
}
}
});
Thank you !!
use async:False to get ajax response one by one
$.ajax({
url: 'backend/publish_auto/update',
async: false,
type: 'post',
data: {},
dataType: 'json',
success: function (result)
{
if(result.st)
{
$('#show').append('Update Coupon ID: '+result.ID+'<br />');
}
}
});
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');
}
});