7*4 2018-10-31 22:33 采纳率: 50%
浏览 36

Sweet Alert TextBox变量

I am very new to PHP and javascript, so my question is fairly simple... I have this JavaScript code (Sweetalert2 text field) And I want to get the information that people type into a separate PHP file using ajax. I am struggling for days now with this problem, would be super grateful if someone showed me how to do it correctly

This is my code

<button type="button" id="new-btn" class="btn btn-primary" onclick="post();">Beitrag Erstellen</button>

<script>

        $(document).ready(function () {

        $('#new-btn').click(function () {
            swal({
                title: "Add Note",
                input: "textarea",
                showCancelButton: true,
                confirmButtonColor: "#1FAB45",
                confirmButtonText: "Save",
                cancelButtonText: "Cancel",
                buttonsStyling: true
            }).then(function () {

                swal(
                    "Sccess!",
                    "Your note has been saved!",
                    "success"

                )
            })
        });
    })

</script>

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33691598 2018-11-01 01:06
    关注

    when you run your code, you will get the below error

    {
      "message": "Uncaught ReferenceError: $ is not defined",
      "filename": "https://stacksnippets.net/js",
      "lineno": 15,
      "colno": 9
    }
    

    "Uncaught ReferenceError: $ is not defined", means that you have used $ symbol syntax, (that is jquery), but you have not imported it properly and defined it. For this purpose, you can add the below lines at the top of your code. Then it should work as expected.

    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
    

    And then, to use swal() in your code, you have to have sweethart script imported which can be done by adding the below one also at the top of your file

    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    

    Finally, your working code file shold be someting like this--->

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js">
    </script>
    <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    </head>
    <body>
    
    <button type="button" id="new-btn" class="btn btn-primary" onclick="post();">Beitrag Erstellen</button>
    
    <script>
    
            $(document).ready(function () {
    
            $('#new-btn').click(function () {
                swal({
                    title: "Add Note",
                    input: "textarea",
                    showCancelButton: true,
                    confirmButtonColor: "#1FAB45",
                    confirmButtonText: "Save",
                    cancelButtonText: "Cancel",
                    buttonsStyling: true
                }).then(function () {
    
                    swal(
                        "Sccess!",
                        "Your note has been saved!",
                        "success"
    
                    )
                })
            });
        })
    
    </script>
    
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line