alex
alex

Reputation: 177

Error : Ajax is Undefined

I am using the below code in a script tag to call one URL in the background.

var request = new Ajax.Request(logoffURL, {method : 'post'});

But I am getting script error Ajax is undefined.

Do I need to include any external scripts?

Upvotes: 0

Views: 12149

Answers (3)

icktoofay
icktoofay

Reputation: 129011

That code uses Prototype. If you want to use that code, you'll need to include Prototype into your page. For example, using Google's CDN:

<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>

Upvotes: 2

dustin999
dustin999

Reputation: 283

Here's a good place to start:

http://api.jquery.com/jQuery.ajax/

As the example shows, you can do something like this:

$.ajax({
  url: logoffURL,
  context: document.body
}).done(function() { 
  alert("DONE");
});

I recommend using a CDN to reference jquery:

https://developers.google.com/speed/libraries/devguide#jquery

Upvotes: 0

Viktor S.
Viktor S.

Reputation: 12815

Yes, you need to include some external script (jQuery, for instance) and learn how to do ajax calls there. There is no Ajax object in browser, but there is XMLHTTPRequest. But again - you must learn how to use it first. For instance - here is how you can use XMLHTTPRequest

Upvotes: 0

Related Questions