开发者

Ajax call using Google Closure

I am new to Google Closure library, and I am trying to simulate something similar to that of Jquery's $.ajax function. Here is what I tried and what I got in response.

The trigger is from Chrome Extensions Right click

chrome.contextMenus.create({"title": "sample_closure", "onclick": samp.myProject.fun1,"contexts":['selection']});

This triggers the fun1 function which is defined as below:

    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);
}

The getAjaxData function is as below.

goog.require("goog.net.XhrIo");

samp.myProject.getAjaxData = function(url) {
   goog.net.XhrIo.send(url, function(event) {
       alert(event.target.getResponseText());
   });
}
开发者_运维百科

But I get this error when I call the getAjaxData function.

Error in event handler for 'contextMenus': TypeError: Cannot read property 'XhrIo' of undefined

Can anyone tell me where I am going wrong.. I checked the Argument type that need to be passed for xhrio.send function and it has string type.


Solved this issue.. The path to base.js is causing this problem.

Not deleting this question because some of you may face the same issue and leaving for them. So, Check your path to base.js of closure-library for solving this issue

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜