为什么我的小工具没有收到数据?

时间:2011-02-23 10:52:06

标签: java google-app-engine google-gadget igoogle

我在appspot上有我的应用程序。这是个人域帐户。

我已将iGoogle小工具放在我的Gmail帐户的iGoogle页面上。

我从我的小工具发送ajax请求,如:

          $(document).ready(function(){
                jQuery.ajax({
                    type: "get",
                    url: "http://searcegadget2.appspot.com/requestServlet",
                    success: function(msg){
                        alert(msg);
                        if(msg.search('tr') != -1){
                            id = msg.split('</tr>').length - 1;
                            //alert(id);
                            $('#amountTable').append(msg);
                            difference();
                        }else if(msg.search('form') != -1){
                            $('#gadget').css('display', 'none');
                            document.write(msg);
                        }else if(msg.search('http') != -1){
                            document.location = msg;
                            $('#amountTable').append(msg);
                        }

                    },error: function(XMLHttpRequest, textStatus, errorThrown){
                        alert("XMLHttpRequest: " + XMLHttpRequest.responseText);
                        alert("textStatus : " + textStatus.responseText);
                        alert("errorThrown : "+ errorThrown);
                    }
                });
            });

XMLHttpRequest&amp ;;中没有显示任何内容。 errorThrown警报。但是,textStatus中显示“错误”!

现在,链接“http://searcegadget2.appspot.com/requestServlet”显示为红色,当我从Mozilla中的Inspect Element打开“http://searcegadget2.appspot.com/requestServlet”时,它返回我也是必需的数据!如何将其附加到我的小工具上?

我的请求servlet在java中。供参考:jQuery.ajax()

另外,我测试了这个Web应用程序。这工作正常!

1 个答案:

答案 0 :(得分:0)

没有看到错误消息或错误代码,很难说出你的问题是什么,但是从你的帖子中,我认为这是一个跨域脚本问题。您无法从其他域执行XMLHttpRequest。 (例如,gmail.com无法对searcegadget2.appspot.com执行XMLHttpRequest而不会抛出错误。)

尝试将 Access-Control-Allow-Origin 标头添加到处理requestServlet端点的控制器的响应中。

有关Access-Control-Allow-Origin标头的详细信息,请参阅此主题:

Access-Control-Allow-Origin Multiple Origin Domains?