无法在 firefox 和 safari 浏览器中设置会话变量 [英] Unable to set session variable in firefox and safari browser

查看:44
本文介绍了无法在 firefox 和 safari 浏览器中设置会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Ajax 设置会话变量,它在 chrome 中运行良好,但在 safari 和 Firefox 浏览器中不起作用

I am setting the session variable using Ajax, its working fine in chrome but not working in safari and Firefox browser

这是我的 Ajax 方法:

This is my Ajax method:

add_action('wp_ajax_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
add_action('wp_ajax_nopriv_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
function wdm_add_user_custom_data_options_callback()
{
    //Custom data - Sent Via AJAX post method
    $product_id = $_POST['custom_data_4']; 
    $custom_data_1 = $_POST['custom_data_1']; 
    $custom_data_2 = $_POST['custom_data_2'];
    $custom_data_3 = $_POST['custom_data_3'];


    $_SESSION['product_idd'] = $product_id;
    $_SESSION['custom_data_1'] = $custom_data_1;
    $_SESSION['product_pos'] = $custom_data_2;
    $_SESSION['product_lmm'] = $custom_data_3;
       die();
}

当我尝试在上面的 Ajax 方法中打印 $_SESSION 和 $_POST 值时,它对所有浏览器都可以正常工作,但是当我尝试在下面的函数中分配上面的会话变量时:-

When I am trying to print the $_SESSION and $_POST value inside above Ajax method its working fine for all browser but when I try to assign above session variable in below function:-

function kia_add_cart_item_data( $cart_item, $product_id ){

   if(isset($_SESSION['product_pos']) && $_SESSION['product_idd']==$cart_item['product_id']){
            $posnumber=$_SESSION['product_pos'];
        }else{
            $posnumber=1;
        }
        if(isset($_SESSION['product_lmm']) && $_SESSION['product_idd']==$cart_item['product_id']){
            $lmmnumber=$_SESSION['product_lmm'];
        }else{
            $lmmnumber=1;
        }

        $array['product_id'] = $product_id;


        $cart_item['product_pos'] = $posnumber;
        $cart_item['product_lmm'] = $lmmnumber;
    return $cart_item;

}

然后我在 Firefox 和 safari 浏览器的情况下获得其他部分价值,而它在 chrome 中运行良好.

Then I am getting else part value in case of Firefox and safari browser while it's working fine in chrome.

请帮助我为什么我没有在 Firefox 和 safari 中获得会话值.

Please help me why I am not getting the session value in Firefox and safari.

推荐答案

实际上我忘记在 jQuery.ajax 中传递 async : false .现在它工作正常.

Actually I was forget to pass async : false inside jQuery.ajax. Now Its working fine.

Async:false 在 ajax 中做了什么

what does Async:false do in ajax

async:false 将保持其余代码的执行.一旦你得到 ajax 的响应,只有这样,其余的代码才会执行​​"

"async:false will hold the execution of rest code. Once you get response of ajax, only then, rest of the code will execute"

这篇关于无法在 firefox 和 safari 浏览器中设置会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆