【发布时间】:2009-12-21 16:06:37
【问题描述】:
我正在创建一个非常基本的 dashcode 小部件。我正在使用来自 Apple 的定制 sn-ps:xmlRequest setup 和 xmlLoaded。下面是我的代码
function sendURL(){
// Values you provide
var textField = document.getElementById("searchqeue"); // replace with ID of text field
var textFieldValue = textField.value;
var feedURL = "feed://isohunt.com/js/rss/"+textFieldValue+"?iht=&noSL"; // The feed to fetch
// XMLHttpRequest setup code
httpFeedRequest = new XMLHttpRequest();
function loadedXML()
{
alert("xmlLoaded");
if (httpFeedRequest.status == 200)
{
// Parse and interpret results
// XML results found in xmlRequest.responseXML
returnvalue = httpFeedRequest.responseText;
alert(returnvalue);
var textField = document.getElementById("resultarea");
textField.value = returnvalue;
// Text results found in xmlRequest.responseText
}
else
{
alert("Error fetching data: HTTP status " + httpFeedRequest.status);
}
}
httpFeedRequest.onload = loadedXML();
alert ("onload executed");
//httpFeedRequest.overrideMimeType("text/html");
httpFeedRequest.open("GET", feedURL);
httpFeedRequest.setRequestHeader("Cache-Control", "no-cache");
// Send the request asynchronously
httpFeedRequest.send(null);
alert("sent");
}
我想把它全部放在一个函数中以保持简单。我当然可以将 xmlLoaded 函数和 sendURL 函数分开,但对我来说这更清楚。
我在错误控制台中返回的代码:
xmlLoaded(loadedXML 函数内第一行)
获取数据时出错:HTTP 状态 0(来自 loadedXML 函数的错误消息)
onload 执行(httpFeedRequest.onload 下面的行 = loadedXML();)
发送(函数的最后一行)
esn-ps 本身带有 dashcode,所以我想问题出在我的网址上。这是一个 feed:// 页面,而不是 html 或 xml 页面。但由于提要也是 xml,我虽然可以只使用 xmlRequest。此外,使用 http:// 而不是 feed:// 调用同一页面会返回相同的结果。
httpFeedRequest.responseText 返回 ""(空字符串)
httpFeedRequest.responseXML 返回 null
任何帮助将不胜感激!
【问题讨论】:
-
同源策略是否应用于dashcode小部件?
标签: javascript xmlhttprequest widget feed dashcode