Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving and Parsing with curl and javascript
hohoman90 Offline
Newbie
*

Posts: 3
Joined: Sep 2006
Post: #1
Retrieving and Parsing with curl and javascript
hey,

I am a relatively new dashboard programmer, however i have had a lot of experience programming in the past. I am puzzled why some code i wrote is not working however. The code takes what the user inputs and sends to a websites api where the access code and input is examined and it returns something like this:
'1','test'
this says that it was successful and the input translates to 'test'.

here is my code (with parts left out for security reasons):
Code:
<!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>
<title>MD5 Lookup Widget</title>
<script language="javascript">

function loadhash() {
var hash = document.GetElementByID("hash").value;

if(hash.length == 30){
var result = widget.system("/usr/bin/curl http:\/\/api.something.com/?hash="+hash+"\&auth=authcodehere",null).outputString;
var length = result.length;
var hashlength = length - 6;

if(result.charAt(1) != '1') {
"Not Found" = document.GetElementByID("result").value;
}
else{
var output = result.substr(5,hashlength);
output = document.GetElementByID("result").value;
}
}
else {
"Invalid MD5 Hash" = document.GetElementByID("result").value;
}
}

</script>
<style>
    body {
        margin: 0;
    }

    .bodyText {
        font: 12px "Verdana";
        font-weight: bold;
        color: white;
        text-align: center;
        position: absolute;
        top: 87px;
        left: 56px;
        width: 180px;
        
    }
</style>

</head>
<body>
<img src="default.png">
<form>
<div class="bodyText">Hash:
<div align="center">
<input name="hash"  type="text" id="hash" size="30" onChange="loadhash()" />
</div>
<br />
<br />
<br />
<br />

Result:
<input name="result" type="text" id="result" size="20" />
</div>
</form>
</body>
</html>
Any help on why this isn't working would be greatly appreciated.

Thanks,
Nick
2006.09.05 03:16 PM
Find all posts by this user Quote this message in a reply
Taxxodium Offline
Moderator
*****

Posts: 324
Joined: Mar 2005
Post: #2
Retrieving and Parsing with curl and javascript
You shouldn't use widget.system() synchronously. Instead, Apple recommends you use it asynchronous for widgets you want to release.

Read this: http://developer.apple.com/documentation...ementID_24

"execute order 66"
2006.09.05 03:30 PM
Visit this user's website Find all posts by this user Quote this message in a reply
hohoman90 Offline
Newbie
*

Posts: 3
Joined: Sep 2006
Post: #3
Retrieving and Parsing with curl and javascript
hmm i tried using endHandler to make it asynchronous, however nothing seems to happen. Is there something i am doing wrong with getting the form data?
2006.09.05 05:37 PM
Find all posts by this user Quote this message in a reply
Taxxodium Offline
Moderator
*****

Posts: 324
Joined: Mar 2005
Post: #4
Retrieving and Parsing with curl and javascript
Try changing GetElementByID to getElementByID

Other than that, use the alert function to debug and check the out in the Console.

You use alert like this:

var myNumber = 5;

alert("Entered number = "+myNumber);

"execute order 66"
2006.09.06 03:39 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)