Responding to Ajax call with JSON

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Responding to Ajax call with JSON

jtuchel
Hi There,

I wonder how I could write an Ajax callback that returns an HTTP 200
response code and a JSOn document as response contents. I am unable to
find any samples for this.

What do I need that for? I want to integrate the X-editable plugin (or
write my own) with Seaside. Since in Seaside, Ajax callbacks always
respond with an HTTP 200 and there is no built-in way of responding with
error codes, I happily found that X-editable has a mode in which it
accepts an HTTP200 and then scans a JSON response for the "real" success
or error info.

Has anybody done that? Maybe even with X-editable? How?

Joachim

--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Responding to Ajax call with JSON

Johan Brichau-2
Hi Joachim,

> What do I need that for? I want to integrate the X-editable plugin (or write my own) with Seaside. Since in Seaside, Ajax callbacks always respond with an HTTP 200 and there is no built-in way of responding with error codes, I happily found that X-editable has a mode in which it accepts an HTTP200 and then scans a JSON response for the "real" success or error info.
>
> Has anybody done that? Maybe even with X-editable? How?

Yes, we’re using X-editable in a project in development. It’s not finished but let me put it online asap.

Johan_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Responding to Ajax call with JSON

Philippe Marschall
In reply to this post by jtuchel
On Tue, Dec 31, 2013 at 2:40 PM, [hidden email]
<[hidden email]> wrote:
> Hi There,
>
> I wonder how I could write an Ajax callback that returns an HTTP 200
> response code and a JSOn document as response contents. I am unable to find
> any samples for this.

I see what you're trying to do there, you're trying to get these in
before Monday ;-)

As others have noted before #respond: gives you full access to the
response allowing you to set any header or content you like:

html submitButton
    onClick: (html jQuery ajax
        respond: [ :response |
            response
                created; "HTTP 201"
                doNotCache;
                contentType: WAMimeType applicationJson.
            response stream nextPutAll: '{"jsonrpc": "2.0", "result":
19, "id": 1}' ]);
    with: 'Replace'

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside