Hi all,

I'm using the Prototype version of Valum's Ajax Uploader...
http://valums.com/ajax-upload/

I have some code in php:

require_once('json/JSON.php');
$this->class_JSON = new Services_JSON();
$arrBar = array("command" => "foo", "response" => $content); //
$content = a string containing a bunch of html
$strFoo = $this->class_JSON->encode($arrBar);
header("Content-Type: application/json; charset=utf-8");
echo $strFoo;


And this (reduced) code in JS:

new AjaxUpload('#upload_button', {
        responseType: 'json',
        onComplete: function(file, response) {
                foo = response.responseText.evalJSON();
                alert("Response:" + foo);
        }
});

Which susseccfully uploads the selected file, yet instead of the
expected Javascript dialog stating [object object], I get a file-
download popup, asking me where I want to save the file of type
"application/json".

If I change the PHP header to text/html or disable it completely, then
I get an "illegal character" error in the JS. A chunk of the beginning
of the response looks like this:

({"command":"foo","response":"\n<input id="\&quot;upload_button
\&quot;"

You can see that the response is garbled; the quotes (and other
characters) are converted to HTML entities, leaving the slashes
behind.

I tried setting the headers to text/javascript, too. No dice. However,
if I do an alert(response) in the code, I can see it all, and it's all
100% correct JSON.

What am I doing wrong?! Surely there must be something fundamental I'm
missing?

Hoping someone can help. I've been battling with this for about 8
hours now :/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to