jQuery Ajax不是函数[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/18271251/typeerror-ajax-is-not-a-function" dir="ltr">TypeError: $.ajax(…) is not a function?</a>
                            <span class="question-originals-answer-count">
                                (11 answers)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/44212202/my-javascript-is-returning-this-error-ajax-is-not-a-function" dir="ltr">My javascript is returning this error: $.ajax is not a function</a>
                            <span class="question-originals-answer-count">
                                (2 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2018-08-10 00:30:24Z" class="relativetime">2 years ago</span>.</div>
        </div>
    </aside>

I have a table with each row looking like this:

<tr id="ID" class="company_row">...</tr>

And a modal:

<div id="company_list_modal"class="modal">
    <p>TEST</p>
</div>

Clicking on the table row should cause a modal to open, done with this:

<script>
$(document).ready(function(){
    const modal = document.getElementById("company_list_modal");
    window.onclick = function(event) {
        if (event.target === modal) {
            modal.style.display = "none";
        };
    };

    $(".company_row").click(function() {
        $.ajax({
            url: "/company/company_info",
            data: {
                "company": $(this).attr('id'),
            },
            dataType: "json",
            success: function(data) {
                console.log(data);
                modal.style.display = "block";
            }
        });
    });
});

The error returned: TypeError: undefined is not a function (near '...$.ajax...')

Efforts to fix:

Selector definitely works - I added a console.log before the ajax bit, which confirmed that the selector and .click bit were fine. (Also confirms that jQuery is definitely loaded).

Have removed the $(this).attr('id'), and replaced it with "test", incase it were causing problems: no change.

Removed all references to the modal from the success function: No change

Tested in chrome and safari, both giving the same result

Update:

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

console.log($.ajax) returns 'undefined'

</div>
查看全部
weixin_33738982
?Briella
2018/08/10 00:19
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

1个回复