Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

jquery

ajax

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

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

Here's where I call it, providing the required parameters:

AJAXrequest('voting.ajax.php', imageData, function(data) {     // function body }); 

Yet, the callback does not run, and instead I get an error in the console:

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

Why? 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 separately-named function. How do I go about this?

like image 570
marked-down Avatar asked Aug 16 '13 10:08

marked-down


People also ask

Why is Ajax not a function?

AJAX is not a programming language. It requires a built-in browser with the XMLHttpRequest object that requests data from the server, and it uses JavaScript and HTML DOM to display data.

How can make AJAX call in jQuery?

The ajax() method in jQuery is used to perform an AJAX request or asynchronous HTTP request. Parameters: The list of possible values are given below: type: It is used to specify the type of request. url: It is used to specify the URL to send the request to.

Is not a function Typeerror is not a function?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.


1 Answers

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.

like image 78
Gus Avatar answered Sep 27 '22 20:09

Gus