Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

XMLHttpRequest is busted! Please help!

Author Message
doubleforte



Joined: 09 Nov 2007
Posts: 1

Posted: Sat Nov 10, 2007 - 12:07 am    Post subject: XMLHttpRequest is busted! Please help! Reply with quote

This is driving me totally batty.

Here's my code:

Code:

function checkForUpdate() {
   var newVerURL = "http://www.doubleforte.net/widgets/symbol-caddy/current-version.html";

   var xmlRequest = new XMLHttpRequest();
   xmlRequest.onload = function(e) {
      alert(xmlRequest.status);
   }
   xmlRequest.open("GET", newVerURL);
   xmlRequest.setRequestHeader("Cache-Control", "no-cache");
   xmlRequest.send(null);
}


This works fine when I run it inside Dashcode, but when it's running in the real Dashboard the responseText is empty. (as seen in Console)

Also, in Dashcode xmlRequest.status = 200...which is right, but in Dashboard, xmlRequest.status comes back as 0.

I've got AllowNetworkAccess set to true and there is nothing strange in Console.

I'm running Leo 10.5.0. Any ideas?
View user's profile Send private message Send e-mail Widgets
seb2



Joined: 04 May 2005
Posts: 41

Posted: Sun Nov 11, 2007 - 1:09 pm    Post subject: Reply with quote

That line
Code:
xmlRequest.onload = function(e)

looks pretty wrong to me. Try
Code:
xmlRequest.onreadystatechange =e;

and then implement function e.

I don't know whether it's the fact that you're using an inline function or whether you're using the wrong trigger...
View user's profile Send private message Send e-mail Widgets
aamann



Joined: 27 Dec 2006
Posts: 5

Posted: Sun Nov 11, 2007 - 3:16 pm    Post subject: Reply with quote

Code:
xmlRequest.onload = function(e) {...}

works just fine (though I am not sure it works for browsers other than WebKit-based - not an issue if you are exclusively targeting the Dashboard) - it is much nicer to use than .onreadystatechange as you won't have to add all that additional code.

I pasted that part of the code into one of my widgets and it works just fine - both in Dashcode and the Dashboard I get
Code:
{
  "version":"2.0"
}

for the responseText.

Apart from the fact that
Code:
xmlRequest.setRequestHeader("Cookie", "");

doesn't work in Leopard (it still sends the cookies stored in Safari instead - reported as bug to Apple), XMLHttpRequest is no busted at all in Leopard.

Could it be that you are re-using your xmlRequest variable for another request and you have a timing issue where it works in one but not the other? Try creating a new variable you only use for the version check and see whether that fixes your problems - you have to keep in mind that the request arte being sent and processed asynchronously.

[/code]
View user's profile Send private message Send e-mail Widgets
rpitting



Joined: 24 Nov 2007
Posts: 1

Posted: Sat Nov 24, 2007 - 12:23 pm    Post subject: Reply with quote

I have a similar issue like doubleforte, except that the code even does not work in Dashcode!

I pasted the code from above and always get only HTTP-Status "0". Even the supplied sample-code from Apple, like the RSS-Reader, do not work!

When debugging the widget, I can see that there is nearly no delay (i. e. no data fetched) between xmlRequest.send and jumping into the load-handler.

Any idea how to produce working widgets?

A hint: I am using the german version of dashcode.

Best regards,


Reiner
View user's profile Send private message Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group