发送请求时,ajax未定义jquery

时间:2018-05-27 16:26:48

标签: javascript jquery ajax

我收到此异常

  

$ .ajax不是函数

在这个波纹管代码中!我做了足够的研究,我没有得到适当的解决方案。我没有使用瘦身版的CDN。我在这个HTML文件中使用bootstrap,它与它有什么关系吗?

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Bootstrap CSS -->
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
     <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">

    <title>Great India</title>
  </head>
  <body>
    <div class="row">
      <div class="col-sm-4">
      </div>
      <div class="col-sm-4">
        <h1>Sign Up</h1>
      </div>
      <div class="col-sm-4">
      </div>
    </div>

    <div class="row">
      <div class="col-sm-4">
      </div>
      <div class="col-sm-4">
        <form>
          <div class="form-group">
            <label for="exampleInputEmail1">Email address</label>
            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
            <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
          </div>
          <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
          </div>
          <div class="form-group form-check">
            <input type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label" for="exampleCheck1">Check me out</label>
          </div>
        </form>
        <button id="signup" class="btn btn-primary">Submit</button>
      </div>
      <div class="col-sm-4">
      </div>
    </div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->


    <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.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
    <script src="rest.js"></script>
    <script>
    $("#signup").click(function()
    {
      var json='{"id":"SomeId","title":"SomeTitle"}';
      var obj=JSON.parse(json);

          $.ajax({
            url:"http://127.0.0.1:8080/signup",
            type: "POST",
            dataType: "json",
            data: obj,
            contentType: "application/json",
            cache: false,
            timeout: 5000,
            complete: function() {
              //called when complete
              console.log('process complete');
            },

            success: function(data) {
              console.log(data);
              console.log('process sucess');
           },

            error: function() {
              console.log('process error');
            },
          });
    });
    </script>
  </body>
</html>

我正在尝试向节点js服务器发送请求。

1 个答案:

答案 0 :(得分:1)

  

我没有使用超薄版的CDN!

你有两个相同的script链接到JQuery min(一个接着一个)和一个到JQuery slim

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

JQuery slim脚本引用位于JQuery min链接之后,因此它覆盖了$引用,而JQuery slim则排除了AJAX功能。

仅供参考:您还有两个与Bootstrap相同的链接。