On Fri, Sep 4, 2009 at 9:48 AM, Alan<alanmand...@gmail.com> wrote:
>
> When you say...
>        Then, in your JS function, test the returned text for
> "failure" or
>        "reject" first, or parse the JSON object and create a new
> image tag
>        with the supplied src, width, & height.
>
> ... what's the exact code for parsing the JSON object within my
> current structure?

Sorry, I left that part out. Check out jquery-json:
http://code.google.com/p/jquery-json/

You might also want to return a JSON object for all outcomes, so you
don't need to check for a string ("failure","reject") *or* a JSON
object.

                $result = array(
                        'result' => 'success',
                        'photo_id' => $newPhotoID,
                        'src' => PATH_FROM_DOCUMENT_ROOT,
                        'width' => THE_WIDTH,
                        'height' => THE_HEIGHT
           );
        }
        else
        {
           $result = array('result' => 'failure');
        }
}
else
{
        $result = array('result' => 'reject');
}

echo json_encode($result);

You'd also be able to supply a message, if you wanted: $result =
array('result' => 'reject', 'msg' => 'just because');


> For instance, I currently submit the form and post a static dialog box
> with the code...
>
>         $('#imageUploader1').ajaxForm(function() {
>                    alert("You just uploaded using Form 1");
>          });
>
> My PHP code now concludes with the following:
>      echo json_encode(array ("result" => "success", "photoID" =>
> $newPhotoID));
>
> I tried replacing my static alert with the following alert (just to
> make sure I'm seeing the data):
>
>         $('#imageUploader1').ajaxForm(function() {
>                    var data = eval('(' + data + ')');
>                    alert("You just uploaded using Form 1 and the
> result was " + data.result);
>          });
>
> Unfortunately, that's not working. What am I missing? Since I'm using
> jquery and jquery form as is, I can't see how to specify the JSON info
> (as I would be able to do if I was manually doing the form
> submission.
>
> Thanks, as always.

Reply via email to