0

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

我在我的 gmail 帐户的 iGoogle 页面上放置了一个 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 和 errorThrown 警报中没有显示任何内容。但是, textStatus 中显示了“错误”!

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

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

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

4

1 回答 1

0

Without seeing an error message or and error code it's hard to tell what your issue is, but from your post, I would think that it's a cross-domain scripting issue. You can't do an XMLHttpRequest from a different domain. (e.g. gmail.com cannot do an XMLHttpRequest to searcegadget2.appspot.com without throwing an error).

Try add the Access-Control-Allow-Origin header to the response of the controller which handles your requestServlet endpoint.

For more information of the Access-Control-Allow-Origin header, see this thread:

Access-Control-Allow-Origin Multiple Origin Domains?

于 2011-02-23T17:46:34.890 回答