CodeIgniter Ajax CSRF Jquery Cookie 方法行为异常

发布于 2024-11-27 11:51:29 字数 2379 浏览 0 评论 0原文

Javascript 部分:

var token = $.cookie("csrf_cookie_name");
var tx = document.getElementById("tx"+working_row).value;
var mods =document.getElementById("mods"+working_row).value;
var pos = document.getElementById("pos"+working_row).value;
var startdate = document.getElementById("startdate"+working_row).value;
var enddate = document.getElementById("enddate"+working_row).value;
var fordx = document.getElementById("4dx"+working_row).value;
var qty = document.getElementById("qty"+working_row).value;
var price = document.getElementById("price"+working_row).value;
obj = new Object();
obj={'csrf_token_name':token,'tx':tx,'mods':mods,'pos':pos,'startdate':startdate,'enddate':enddate,'fordx':fordx,'qty':qty,'price':price};
alert(obj.csrf_token_name);
$.post("index.php/auth/fee_schedule",obj, function(data){
    alert(data);
});

我遇到的问题是令牌变量未包含在帖子中。我不知道为什么。警报是 [Object Object],因此为 null。页面的标题如下:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Medata Preauthorzation System</title>
    <link rel="stylesheet" href="<?php echo base_url();?>css/screen.css" type="text/css" media="screen">
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery.sexy-combo.min.js"></script>
    <link rel="stylesheet" href="<?php echo base_url();?>css/jquery-ui-1.8.13.custom.css" type="text/css" media="screen">
    <link rel="icon" type="image" href="/medata/favicon.ico">
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery.impromptu.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/cookie.js"></script>
</head>

因此包含了库函数和 Cookie 函数。我在同一页面上使用 cookie 函数 10 次来发帖,它工作正常,但我没有将它们中的任何一个放入具有其他变量的对象中,所以它只是内联阿拉

$.post("index.php/auth/tx_history/"+tx_code, { csrf_token_name: $.cookie("csrf_cookie_name") }, function(data){
    //alert(data);
        $("#price"+rowid).val(data);
});

我喜欢一些建议,我已经整个下午的大部分时间我都在为这段代码不停地思考问题。

Javascript Section:

var token = $.cookie("csrf_cookie_name");
var tx = document.getElementById("tx"+working_row).value;
var mods =document.getElementById("mods"+working_row).value;
var pos = document.getElementById("pos"+working_row).value;
var startdate = document.getElementById("startdate"+working_row).value;
var enddate = document.getElementById("enddate"+working_row).value;
var fordx = document.getElementById("4dx"+working_row).value;
var qty = document.getElementById("qty"+working_row).value;
var price = document.getElementById("price"+working_row).value;
obj = new Object();
obj={'csrf_token_name':token,'tx':tx,'mods':mods,'pos':pos,'startdate':startdate,'enddate':enddate,'fordx':fordx,'qty':qty,'price':price};
alert(obj.csrf_token_name);
$.post("index.php/auth/fee_schedule",obj, function(data){
    alert(data);
});

The issue I'm having is that the token variable isn't being included in the post. I'm not sure why. The Alert is [Object Object] so, null. The header of the page has the following:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Medata Preauthorzation System</title>
    <link rel="stylesheet" href="<?php echo base_url();?>css/screen.css" type="text/css" media="screen">
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery.sexy-combo.min.js"></script>
    <link rel="stylesheet" href="<?php echo base_url();?>css/jquery-ui-1.8.13.custom.css" type="text/css" media="screen">
    <link rel="icon" type="image" href="/medata/favicon.ico">
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery.impromptu.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url();?>js/cookie.js"></script>
</head>

So the Library and Cookie Functions are included. I use the cookie function 10 other times on the same page to do posts and it works fine, but I don't put any of them into objects with other variables, so it's just inline alla

$.post("index.php/auth/tx_history/"+tx_code, { csrf_token_name: $.cookie("csrf_cookie_name") }, function(data){
    //alert(data);
        $("#price"+rowid).val(data);
});

I'd Love some Suggestions, i've been hitting my head against this code most of the afternoon for non-stop issues.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や莫失莫忘 2024-12-04 11:51:30

或许:

var token = $.cookie("<?php echo $this->config->item("csrf_cookie_name"); ?>");

Maybe:

var token = $.cookie("<?php echo $this->config->item("csrf_cookie_name"); ?>");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文