javascript 错误:Ajax 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12303347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error : Ajax is Undefined
提问by alex
I am using the below code in a script tag to call one URL in the background.
我在脚本标签中使用以下代码在后台调用一个 URL。
var request = new Ajax.Request(logoffURL, {method : 'post'});
But I am getting script error Ajax is undefined
.
但我收到脚本错误Ajax is undefined
。
Do I need to include any external scripts?
我需要包含任何外部脚本吗?
回答by icktoofay
回答by Viktor S.
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 - hereis how you can use XMLHTTPRequest
是的,您需要包含一些外部脚本(例如jQuery)并学习如何在那里进行 ajax 调用。浏览器中没有 Ajax 对象,但有 XMLHTTPRequest。但同样 - 您必须先学习如何使用它。例如 -这里是如何使用 XMLHTTPRequest
回答by dustin999
Here's a good place to start:
这是一个很好的起点:
http://api.jquery.com/jQuery.ajax/
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:
我建议使用 CDN 来引用 jquery:
https://developers.google.com/speed/libraries/devguide#jquery
https://developers.google.com/speed/libraries/devguide#jquery