最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error : Ajax is Undefined - Stack Overflow

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论