Hi,

"application/json" is the correct MIME type.[1]  I suspect the issue
is in the third-part component you're using.  I haven't had any
trouble doing Ajax requests and getting back JSON.

Note that (with plain Prototype ajax requests) if the content type
comes back application/json, you *don't* have to call evalJSON, just
reference the responseJSON property[2] of the response:

    new Ajax.Request("somethingThatReturnsJSON.php", {
        onSuccess: function(response) {
            alert(response.responseJSON);
        }
    });

I don't think that solves your problem, but once you do solve your
problem that may make your code a bit more efficient (calling evalJSON
just means it gets eval'd twice).

[1] http://www.ietf.org/rfc/rfc4627.txt
[2] http://api.prototypejs.org/ajax/ajax/response.html

FWIW,
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com


On Sep 26, 9:27 pm, plankmeister <plankmeis...@gmail.com> wrote:
> 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