Forum Moderators: travelin cat

Message Too Old, No Replies

Widget choking on non-ASCII characters

Unix 'curl' might be causing the failure

         

timster

12:20 pm on Jul 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm writing a Dashboard Widget that curls records from my web app, but the widget chokes on any string containing non-ASCII characters. (The site uses character set (iso-8859-1).)

Here's the code snippet:

var commandLine = '/usr/bin/curl http://www.mysite.com/some_xml.php'
var output = widget.system(commandLine, null).outputString;
document.getElementById('data').innerHTML = output

The data div contains "undefined" as the string value if there's an accented character, etc.

It looks like

curl
doesn't understand the non-ASCII character and hands the Widget something that makes it choke.

Any suggestions to solve or eschew this problem?

jezra

8:56 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



You could try seting the character encoding of the widgets HTML page to your specified character set. You may also want to check for any header output generated by the curl request that might cause a conflict when entered into a div. Using the php function htmlentities() on your servers outputted text may also solve the problem.

On a side note, if you are gathering XML formatted data from your server, you may want to use XMLHttpRequest [developer.apple.com] to gather your data.

timster

12:22 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jezra. I've got things working with your help.

Regarding htmlentities(), when I originally tried this the xml parser complained about the entities that were created (didn't like à if I recall). So I used the xmlentities() function contributed on this page:

[us2.php.net ]

You mentioned:

check for any header output generated by the curl request

I did this by running the curl command in Terminal, but didn't see anything. Am I missing something there?

Although it's working, I will check out XMLHttpRequest since that looks like it may be the way of the future here.

jezra

4:41 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



Header output from the server can be checked using the "-D" option in curl. To get the headers sent from a web page:

curl http://www.example.com/some_script.php -D header.txt

the requested page will be displayed and the headers will be written to the file "header.txt". I would like to know what the solution to your problem was. If you do decide to use XMLHttpRequest, be sure to put
header("Content-type: text/xml");
at the beginning of your output script or the xml parser will choke and you might end up pulling out your hair for a few hours trying to figure our what is wrong :) .

timster

5:31 pm on Jul 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what the solution to your problem was

The Widget uses XML gathered from a PHP page. I encoded the characters with the xmlentities function (see link above) and that solved the problem.

I'll look into XMLHTTPRequest later (maybe much later) and post how that goes.