PDA

View Full Version : Dashcode Ajax request issue.




Killyp
Jul 12, 2007, 11:01 AM
I have been trying to create a widget to request a server and display the number of email messages you have using Dashcode.

However, the XMLHTTP request object seems to be aborting before doing anything. The readystate property is set to 4 and the status is set to 0, According to what I have discovered from the internet, this means it has aborted. I am sure my URL is correct, yet it still won't work.

Here is my code:


var xmlhttp = create_object(); //this creates the xmlhttprequest object, I know this works as its been tested in browsers, safari (3), firefox and IE
xmlhttp.open('POST', 'http://boshty.co.uk/mail/list_messages.php', true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200)
{
//request worked
}
else
{
//error, this is where we always end up. Ready state 4, status 0.
}
}
}
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //because we are sending data
xmlhttp.send("f=inbox"); //this needs to be sent.


Thanks in advance :)



linuxftw
Jul 15, 2007, 12:10 PM
I am having the same issue. Anybody got any hints?

superbovine
Jul 15, 2007, 05:30 PM
You didn't say what error you were getting my guess is you ran into a cross-domain issue.

you can google for cross-domain widget or xmlhttprequest etc. Yahoo has a pretty good diagram of what is going on there is several techinques to get around it.

http://developer.yahoo.com/javascript/howto-proxy.html
http://ajaxian.com/archives/how-to-make-xmlhttprequest-calls-to-another-server-in-your-domain
http://forums.widgetbox.com/viewtopic.php?pid=36

linuxftw
Jul 23, 2007, 02:57 PM
It seems XMLHTTP Request object gives no error. It just aborts.

Is there any way I can extract an error from it?

inCider
Jan 17, 2008, 12:04 PM
Make sure you are allowing for network access in your Info.plist file:

<key>AllowNetworkAccess</key>
<true/>

HTH,
inCider