I'm creating a very basic dashcode widget. I'm using customized snippets from Apple: xmlRequest setup and xmlLoaded. Below is my code
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");
}
I want to keep it all in one single function to keep it simple. I could ofcourse separate the xmlLoaded function and the sendURL function but for me this is clearer.
the code I get back in the error console:
xmlLoaded (inside the loadedXML function first line)
Error fetching data: HTTP status 0 (the error message from the loadedXML function)
onload executed (the line beneath httpFeedRequest.onload = loadedXML();)
sent (the last line of the function)
Thes esnippets come with dashcode itself, so I guess the problem is with my url. This is a feed:// page instead of a html or xml page. But as feeds are xml too, I though I could just use the xmlRequest. Also, calling the same page with http:// instead of feed:// returns the same.
httpFeedRequest.responseText returns "" (empty string)
httpFeedRequest.responseXML returns null
any help will be more than appreciated!