我在应用程序的脚本部分中动态加载Mootools(AutoWWW),因为它不允许直接使用HTML。Mootools Request.HTML返回undefined
我正在使用Request.HTML并希望获取页面的html,但它返回一个'undefined'消息。我怎样才能解决这个问题?
我的代码:
function loadScript(url, callback) {
// Adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
script.onload = callback;
// Fire the loading
head.appendChild(script);
}
var mootools = new Request({
url: 'http://google.com',
method: 'get',
onSuccess: function(responseText){
alert(responseText);
}
});
loadScript("https://ajax.googleapis.com/ajax/libs/mootools/1.6.0/mootools.min.js", mootools);
不知道正是你正在尝试做的,你能解释一下更好?对我来说,看起来你正试图在MooTools库加载前从MooTools的方法加载MooTools库,它不是CDN的MooTools网站。 – Sergio
我刚刚编辑我的帖子,并更改请求的网址,因为它很混乱,我已经将它设置到主页来测试。基本上我想通过GET返回像google.com这样的网址的HTML,并将其显示在警报中。 loadScript函数不是mootools,函数应该工作并加载mootools.min.js,然后调用使用库运行GET请求的mootools回调函数。 – zeddex