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 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
本文标签: javascriptErrorAjax is UndefinedStack Overflow
版权声明:本文标题:javascript - Error : Ajax is Undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745196480a2647161.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论