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?
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?
Share Improve this question edited Sep 7, 2012 at 2:27 Taryn East 27.8k9 gold badges88 silver badges110 bronze badges asked Sep 6, 2012 at 15:23 alexalex 1791 gold badge4 silver badges21 bronze badges3 Answers
Reset to default 2That 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./ajax/libs/prototype/1.7.1.0/prototype.js"></script>
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
Here's a good place to start:
http://api.jquery./jQuery.ajax/
As the example shows, you can do something like this:
$.ajax({
url: logoffURL,
context: document.body
}).done(function() {
alert("DONE");
});
I remend using a CDN to reference jquery:
https://developers.google./speed/libraries/devguide#jquery