Excellent, that solved my problem.

Many thanks.

On 27/10/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> You may need this :
>
> req.setRequestHeader("Content-type",
> "application/x-www-form-urlencoded");
>
> Lee McFadden wrote:
> > I'm having some troubles POSTing data using an XMLHttpRequest.  I've
> > tried various permutations of the following method, to no avail.
> >
> > I'm following the suggestions posted by Bob Ippolito on his blog[1].
> >
> > I have the following javascript in my page:
> >
> > [code]
> >         // create var data here...  this is a big dictionary, so it's
> > excluded. :)
> >       var updateReq = getXMLHttpRequest();
> >
> >       var postString = queryString(data);
> >       updateReq.open('GET', 'test?' + postString, true);
> >       var result = sendXMLHttpRequest(updateReq)
> >
> >       result.addCallback(saveHandler);
> > [/code]
> >
> > The test method is extremely simple:
> >
> > [code]
> >
> >       @turbogears.expose()
> >       def test(self, *args, **kw):
> >               return "args: %s"%str(args) + "kw: %s"%str(kw)
> >
> > [/code]
> >
> > This works with no problems at all.
> >
> > However, if I try and make the XMLHttpRequest a POST method:
> >
> > [code]
> >         // create var data here...  this is a big dictionary, so it's
> > excluded. :)
> >       var updateReq = getXMLHttpRequest();
> >
> >       var postString = queryString(data);
> >       updateReq.open('POST', 'test', true);
> >       var result = sendXMLHttpRequest(updateReq, queryString)
> >
> >       result.addCallback(saveHandler);
> > [/code]
> >
> > ... the returned string is "args: [] kw: {}".
> >
> > Even stranger, if I keep the format for updateReq.open() with the
> > queryString appended to 'test?' CherryPy doesn't seem to return
> > *anything*
> >
> > [code]
> > 127.0.0.1 - - [2005/10/27 13:57:24] "GET /news/view?id=1 HTTP/1.1" 200 3452
> > 2005/10/27 13:57:24 HTTP INFO 127.0.0.1 - GET /tg_js/MochiKit.js HTTP/1.1
> > 127.0.0.1 - - [2005/10/27 13:57:24] "GET /tg_js/MochiKit.js HTTP/1.1" 304 -
> > 2005/10/27 13:57:24 HTTP INFO 127.0.0.1 - GET /favicon.ico HTTP/1.1
> > 127.0.0.1 - - [2005/10/27 13:57:24] "GET /favicon.ico HTTP/1.1" 200 70
> > 2005/10/27 13:57:27 HTTP INFO 127.0.0.1 - POST
> > /news/test?id=1&headline=Welcome%20to%20the%20U%26S%20Website&body=%3Cdiv%20class%3D%22document%22%3E%0A%3Cp%3EThis%20is%20the%20body%20text.%20%20Nothing%20to%20see%20here%3C%2Fp%3E%0A%3C%2Fdiv%3E%0A&categoryid=1
> > HTTP/1.1
> >
> > [/code]
> >
> > The server just sits there until another request is made (at which
> > point the response is sent out with a 200 code).
> >
> > is there something that I'm doing wrong here to make either the
> > JavaScript or CherryPy misbehave?
> >
> > Sorry for the long post, and thanks in advance.
> >
> > Lee
> >
> > [1] http://bob.pythonmac.org/archives/2005/09/09/mochikit-cons-or-not/
>
>

Reply via email to