【问题标题】:How to fix '$.ajax' not defined?如何修复 \'$.ajax\' 未定义?
【发布时间】:2023-02-11 01:49:06
【问题描述】:

我已经制作了简单的 CRUD Laravel,然后我尝试在多个表中制作具有搜索功能的简单 ORM。 当我在我的数据结果中使用 jQuery 时出现问题,我收到错误:

$.ajax not defined

这是我的results.js

$(document).ready(function () {
    ...
    $.ajax({
    ...
    });
});

这是我的layout.blade.php

<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>NCI ORM App Example</title>
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
   </head>
   <body>
      <style>
      ...
      </style>
      <div class="container">
         @yield('content')
      </div>
      <script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha384-xxxxxxxxxxxxxxxx" crossorigin="anonymous" type="text/javascript"></script>
      <script src="https://code.jquery.com/jquery-3.6.3.slim.min.js" integrity="sha384-xxxxxxxxxxxxxxxx" crossorigin="anonymous" type="text/javascript"></script>
      <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" type="text/js"></sc>
      <script type="text/javascript" src="{{ asset('results.js') }}"></script>
   </body>
</html>

我试图生成一个新的完整性并在&lt;script&gt;中添加typ="text/javascript"并将$.ajax更改为jQuery.ajax,仍然无法正常工作。

提前致谢。

【问题讨论】:

  • 在标头中移动 jquery 库,以便它在 ajax 调用之前加载

标签: jquery ajax laravel


【解决方案1】:

这是功能代码:

<html>
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>NCI ORM App Example</title>
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
   </head>
   <body>
      <div class="container">
        
      </div>
      <script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
      <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" type="text/js"></sc>
       <script>
         $(document).ready(function () {
            $.ajax({});
         });
         </script>
   </body>
</html>

只需使用我的 jQuery 导入脚本。来源:https://releases.jquery.com/

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 2022-01-20
    • 2020-01-26
    相关资源
    最近更新 更多