【问题标题】:jQuery .post() function doesn't work with BootstrapjQuery .post() 函数不适用于 Bootstrap
【发布时间】:2018-12-01 12:43:52
【问题描述】:

一段时间以来,我无法使发布功能正常工作。我已经尝试了我在互联网上找到的所有内容,但似乎没有任何帮助。 这些是我的文件:

<html>
<head>
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

  <script>
  $(document).ready(function(){
    $("#sendButton").click(function(){
      event.preventDefault();
      var text = document.getElementById("xd").value;
      $.post("reg_send.php",
      {
          name: text
        },
        function(data){
          $("#xd").html(data);
        });
        $("#xd").html("Trying");
    });
  });
  </script>

</head>
<body>
  <form style="width: 70%; margin: 0 auto;">
    <p id="xd">TextHere</p>
    <button type="button" class="mx-auto btn btn-danger" id="sendButton" data-toggle="collapse" data-target="#collapse1">Enviar</button>
  </form>

</body>
</html>

还有 reg_send.php 文件:

<?php
echo "working";
?>

但它不起作用,我不知道为什么。我也尝试过使用它,但没有:

  <script>
    function send(){
     $.post('reg_send',{},
      function(data){
        $("#Titulo").html("Xd");
      });

      }
  </script>

并在按钮的 onClick 上调用 send()。我想使用薄的 XAMPP 服务器,也尝试在那里设置它,但什么也没有。 提前致谢。

【问题讨论】:

    标签: jquery html ajax post xampp


    【解决方案1】:

    这里,您使用的是 jQuery 的精简版,它没有 AJAX 的 $.post() 功能。

    使用完整的构建,可在此处获得http://jquery.com/download/,例如:

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

    【讨论】:

      【解决方案2】:

      jquery slim不提供对ajax方法的支持为了在jquery中使用ajax你需要使用jquery.min.js或者jquery.js

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      
      <script>
          $(document).ready(function(){
              $("#sendButton").click(function(){
                  $.ajax({
                      type: 'POST',
                      url: 'reg_data.php', 
                      data: 'Hello'
                  })
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-06-22
        • 1970-01-01
        • 2016-02-21
        • 1970-01-01
        • 2011-05-24
        • 2017-05-05
        • 1970-01-01
        相关资源
        最近更新 更多