使用Google Closure进行Ajax调用
|
我是Google Closure库的新手,我正在尝试模拟类似于Jquery的$ .ajax函数的东西。这是我尝试过的以及得到的回应。
触发来自Chrome扩展程序右键单击
chrome.contextMenus.create({\"title\": \"sample_closure\", \"onclick\": samp.myProject.fun1,\"contexts\":[\'selection\']});
这将触发fun1函数,其定义如下:
samp.myProject.fun1 = function(info,tab) {
var string_url = info.selectionText;
//String_url works fine and passed to the function below.
samp.myProject.getAjaxData(string_url);
}
getAjaxData函数如下。
goog.require(\"goog.net.XhrIo\");
samp.myProject.getAjaxData = function(url) {
goog.net.XhrIo.send(url, function(event) {
alert(event.target.getResponseText());
});
}
但是,当我调用getAjaxData函数时出现此错误。
Error in event handler for \'contextMenus\': TypeError: Cannot read property \'XhrIo\' of undefined
谁能告诉我我要去哪里哪里..我检查了需要传递给xhrio.send函数的Argument类型,它具有字符串类型。
没有找到相关结果
已邀请:
1 个回复
屉杆绊