Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $.ajax is not a function how to solve WITH MY CODE)?

When i click on the button, this error is blow up! help pls When i click on the button, this error is blow up! help pls

TypeError: $.ajax is not a function

$(document).on('click', '.item_add', function(e){
        e.preventDefault();
        product_id          = $(".product_id").html();
        product_name        = $(".product_name").html();
        product_price       = parseFloat($(".item_price").html())   
        product_size        = $(".bann-size").val();
        url                 = '/basket_adding/'
        var data            = {};
        data.product_id     = product_id
        data.product_name   = product_name
        data.product_price  = product_price
        data.product_size   = product_size

        $.ajax({
            url: url,
            type: 'POST',
            data: data,
            cache: true,
            success: function(data){
                console.log("OK");


            },
            error: function(data){
                console.log(data + "ERROR")
                alert("Something wrong, try again!")
                location.reload();
            }
        });
    });
like image 302
InvictusManeoBart Avatar asked Sep 20 '17 10:09

InvictusManeoBart


People also ask

What causes an AJAX error?

Many pages send AJAX requests to a server. Because this relies on the cooperation of the server and the network between the client and the server, you can expect these AJAX errors: Your JavaScript program receives an error response instead of data; Your program has to wait too long for the response.

Can we write AJAX in JavaScript?

Ajax is a programming concept. Below are some ways to make Ajax call in JavaScript. Approach 1: In this approach, we will use the XMLHttpRequest object to make Ajax call. The XMLHttpRequest() method which create XMLHttpRequest object which is used to make request with server.

What is AJAX function in JavaScript?

AJAX stands for Asynchronous JavaScript And XML. In a nutshell, it is the use of the XMLHttpRequest object to communicate with servers. It can send and receive information in various formats, including JSON, XML, HTML, and text files.

What is jQuery AJAX ()?

What is AJAX? AJAX = Asynchronous JavaScript and XML. In short; AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. Examples of applications using AJAX: Gmail, Google Maps, Youtube, and Facebook tabs.


1 Answers

It sounds like you could be using jquery slim which doesn't have ajax support. Use:

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

for ajax support

like image 166
MattjeS Avatar answered Oct 22 '22 19:10

MattjeS