TypeError: $.ajax(...) is not a function?

ReactingToAngularVues picture ReactingToAngularVues · Aug 16, 2013 · Viewed 386.7k times · Source

I'm trying to create a simple AJAX request which returns some data from a MySQL database. Here's my function below:

function AJAXrequest(url, postedData, callback) {
    $.ajax() ({
        type: 'POST',
        url: url,
        data: postedData,
        dataType: 'json',
        success: callback
    });
}

...and here's where I call it, parsing in the required parameters:

AJAXrequest('voting.ajax.php', imageData, function(data) {
    console.log("success!");
});

Yet, my success callback does not run (as "success!" is not logged to the console), and I get an error in my console:

TypeError: $.ajax(...) is not a function.
success: callback

What does this mean? I've done AJAX requests before where the success event triggers an anonymous function inside of $.ajax, but now I'm trying to run a separate named function (in this case, a callback). How do I go about this?

Answer

Gus picture Gus · Nov 21, 2016

Neither of the answers here helped me. The problem was: I was using the slim build of jQuery, which had some things removed, ajax being one of them.

The solution: Just download the regular (compressed or not) version of jQuery here and include it in your project.