admin管理员组

文章数量:1415145

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 badges
Add a ment  | 

3 Answers 3

Reset to default 2

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./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

本文标签: javascriptErrorAjax is UndefinedStack Overflow