简体   繁体   English

使用ajax将数据传递到php

[英]passing data to php using ajax

this is not my first time to use ajax on my website but right now im really confused whats wrong with it. 这不是我第一次在我的网站上使用Ajax,但现在我真的很困惑它的问题所在。 i even removed the important codes. 我什至删除了重要的代码。 what im doing right now. 我现在在做什么。 is to check if ajax is passing the data to the php or not. 是要检查ajax是否将数据传递给php。

 <script type='text/javascript'>
        $(document).ready(function () {
            $('.btndeclineme').click(function () {
                    var docreason = document.getElementById("docreason");
                    if (docreason !== null && docreason.value === "")
                    {
                      $('#reasonalert').show();
                      return;
                    }else{
                        var signatoryidglobal = JSON.parse('<?php echo json_encode($_SESSION['signatoryid']); ?>');
                        alert(signatoryidglobal);

                        $('#reasonalert').hide();

                                $.ajax({
                                        type: "POST",
                                        url: "sample.php",
                                        data: ({dtsignatory: signatoryidglobal})
                                    })
                                    .done(function (msg) {
                                    alert( "Data:" + msg);

                                    })
                            .fail(function() {
                                alert( "Posting failed." );
                            }); 
                    };
            });
        });
  </script>

and this is the sample.php 这是sample.php

<?php 

    $temp1 = $_POST['dtsignatory'];

echo $temp1;

?>

my problem is its not showing errors. 我的问题是它没有显示错误。 isn't it supposed to promp the data i passed to the php because of alert( "Data:" + msg); 是不是因为alert(“ Data:” + msg)来提示我传递给php的数据? but it keeps showing nothing. 但它一直不显示任何内容。

i even add a alert prompt to check if the variable has a value. 我什至添加了警报提示,以检查变量是否具有值。 and it has a value. 它具有价值。 sorry for my bad english. 对不起,我的英语不好。 i hope my question is clear 我希望我的问题清楚

 $.ajax({
     type: "POST",
     url: "sample.php",
     data: {
         dtsignatory: signatoryidglobal
     },
     headers: {
         "Accept": "application/json; charset=utf-8"
     },
     contentType: "application/json; charset=utf-8",
 })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM