为什么我的小工具无法接收数据?
我在 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 & 中没有显示任何内容。错误引发警报。但是,textStatus 中显示“错误”!
现在,链接“http://searcegadget2.appspot.com/requestServlet”显示为红色,当我从 Mozilla 中的 Inspect Element 打开“http://searcegadget2.appspot.com/requestServlet”时,它会返回所需的内容数据也是如此!如何将其连接到我的小工具上?
我的请求servlet是用java编写的。供参考:jQuery.ajax()
另外,我已经测试了这个网络应用程序。即工作正常!
I have my application on appspot. This is on personal domain account.
I have put an iGoogle Gadget on iGoogle Page of my gmail account.
I am sending ajax request from my gadget like :
$(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);
}
});
});
There is nothing shown in XMLHttpRequest & errorThrown alerts. But, there is "error" shown in textStatus !
Now, the link "http://searcegadget2.appspot.com/requestServlet" is shown in red and when I open the "http://searcegadget2.appspot.com/requestServlet" from Inspect Element in Mozilla, it returns me the required data as well ! How do I attach it to my gadget ?
My request servlet is in java. For reference : jQuery.ajax()
Also, I have tested this web application. That is working properly !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有看到错误消息或错误代码,很难判断您的问题是什么,但从您的帖子来看,我认为这是一个跨域脚本问题。您不能从不同的域执行 XMLHttpRequest。 (例如,gmail.com 无法在不抛出错误的情况下对searcegadget2.appspot.com 执行XMLHttpRequest)。
尝试将 Access-Control-Allow-Origin 标头添加到处理 requestServlet 端点的控制器的响应中。
有关 Access-Control-Allow-Origin 标头的更多信息,请参阅此线程:
访问控制允许来源多源域?
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?