cleft cleft - 5 months ago 21
Javascript Question

Ajax not working - keep getting $.ajax is not a function error

No matter what I do I keep getting the same error "

$.ajax
is not a function" and I can't seem to figure it out.

I have been working on this for a while and this is what I have tried.

My Debugging / Troubleshooting Steps -
(I am laying this out so it will be a resource to help easily resolve more common problems.)

1. jQuery is installed.

Ran the following test:

$(document).ready(function() {
console.log($.ajax);
alert('pre test success');
if(window.jQuery) {
alert('post test success');
} else {
alert('test fail Jquery did not load!');
}
});




2. Tested current and previous versions of jQuery (I am NOT using slim release).

(Note: it appears the slim version does not include Ajax)

I have even tried to include Ajax library completely seperate along with jQuery library using jQuery Builder at http://projects.jga.me/jquery-builder/

3. Tested many different syntax to help eliminate syntax error.

For example from answer to similar question on stack overflow:

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


Even this one directly from the jquery home page:

$.ajax({
url: "/api/getWeather",
data: {
zipcode: 97201
},
success: function( result ) {
$( "#weather-temp" ).html( "<strong>" + result + "</strong> degrees");
}
});


I have also tried to change
$.ajax
to
jQuery.ajax
etc with no luck.

4. Confirm I am using document ready

See code for #1
alert('pre test success');


5. Confirm jQuery library is included before script with Ajax.

Check



It seems no matter what I do nothing solves this problem. And for the what it' worth I am running this on XAMP and DigitalOcean server and getting the same results.

Any suggestions?

Answer Source

maybe are you using other libraries which could mess up with the use of the $ sign ?

Have a look there : Avoiding Conflicts with Other Libraries (jQuery)