Jump to content


AJAX Problem


  • You cannot reply to this topic
No replies to this topic

#1 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 23 December 2007 - 07:02 AM

I'm following a tutorial on Issue #137 of Web Designer which is about creating an AIR app from a Ajax one.

The problem I face now is that the script provided by them don't work.

I'm getting an error in Firefox:
uncaught exception: Permission denied to call method XMLHttpRequest.open

To update you guys about what the script does, it's a mini app to update your status in Twitter.

Here's my code which does not work both in Firefox and IE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Twitter Submitter</title>

<script>

var updateURL="http://twitter.com/statuses/update.xml";

function postMe() {

	username=document.twitterform.uname.value;
	password=document.twitterform.passwd.value;
	text=document.twitterform.updatetext.value;
	
	if(text.length == 0) {
		alert("No text!");
		return false;
	}
	
	if(text.length >= 130) {
		alert("Too long!");
		return false;
	}
	
	var content = "source=twitAIR&status=" + encodeURIComponent(text);
	
	showStatus("Posting message");
	submitUpdate(updateURL,content,function (istimeout){
		if( xml && (xml.readyState == 4 || istimeout == "timeout") ) {
			showStatus("Message Posted");
		}
	});
	
}

function showStatus(message) {

	document.getElementById('status').innerHTML = message;
	
}

function submitUpdate(uri,message,callback){
	
	alert("In Post");
	xml = new XMLHttpRequest();
	xml.open("POST",uri,true,username,password);
	xml.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
	xml.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xml.onreadystatechange = callback;
	xml.send(message);
	
}

</script>

</head>

<body bgcolor="#000000">

<div align="center" style="background-color:#000000;color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;padding:20px;">

<p><strong>Ready to Post!!</strong></p>

<div id="status">
</div>

<p>What are you doing?</p>
<form name="twitterform">
  <label>
  <textarea name="updatetext" id="message" cols="45" rows="5"></textarea>
  </label>
  <p>Username: 
	<label>
	<input type="text" name="uname" id="uname" />
	</label>
  </p>
  <p>Password: 
	<label>
	<input type="password" name="passwd" id="pword" />
	</label>
  </p>
  <p>
	<label>
	<input type="button" onclick="postMe();" value="Twit!" />
	</label>
</p>
</form>

</div>
</body>
</html>

However, after changing a line, I managed to make it work in IE:
xml = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0")

Attached is the HTML file if anyone needs it.

Note: Although it works in IE, packaging it as an AIR app did not work as well.

Attached Files







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users