2010/5/4 Rob <robertastanfi...@gmail.com>

> That did the trick, I love you man! :O)
>
>
:-)


> Now, how would I perform the same with a POST if I needed to?
>
>
If you want to POST your data as key/value pairs like with GET, and jQuery
puts it into the body of the request instead of the query string (i don't
know the implementation details, request parameters as query string are just
fine even if it is a POST request) you have to make sure that the
contentType is the default "application/x-www-form-urlencoded". Just give it
a try.

However, if you want to post the data as JSON fragment (as i would assume
from your original post from the contentType of "application/json"), i think
setting "processData" to "false" could do it. But in your servlet you won't
get the values as request parameters anymore. Instead you have to parse the
input stream of the request, e.g. with Gson to a Java object.

regards,
Stephan


>
> On May 4, 2:07 am, Stephan Hartmann <hartm...@metamesh.de> wrote:
> > if you want to get your data as request parameter, you should use "GET"
> > instead of "POST" and /or let the default contentType
> > "application/x-www-form-urlencoded" and create your json object as either
> >
> >     var json = {name: "test"};  // and let jquery convert it to a query
> > string
> > or
> >     var json = "name=test";   // the desired query string
> >
> > regards,
> > Stephan
> >
> > 2010/5/4 Rob <robertastanfi...@gmail.com>
> >
> >
> >
> >
> >
> > > I'm running Google App Engine through IntelliJ Idea and am posting
> > > data to a Servlet using jQuery.ajax. I'm hitting the Servlet without
> > > issue and can return data in the response, however, the request
> > > parameters are always null; I cant seem to POST data. Where am I going
> > > wrong?
> >
> > > var json = JSON2.stringify({name: "test"});
> >
> > > $.ajax({
> > >            type: "POST",
> > >            url: service,
> > >            data: json,
> > >            contentType: "application/json; charset=utf-8",
> > >            dataType: "json",
> > >            async: async,
> > >            success: function(o) {
> > >                 o = $.serviceHelper.jsonSerialize(o);
> > >                   callback(o);
> > >            },
> > >            error: this.dataServiceError
> > >        });
> >
> > >    protected void doPost(javax.servlet.http.HttpServletRequest
> > > request, javax.servlet.http.HttpServletResponse response) throws
> > > javax.servlet.ServletException, IOException {
> >
> > >        PrintWriter out = response.getWriter();
> > >        response.setContentType("text/json");
> > >        String json = gson.toJson(request.getParameter("name"));
> > >        out.println(json);
> >
> > >    }
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Google App Engine for Java" group.
> > > To post to this group, send email to
> > > google-appengine-j...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com><google-appengine-java%2B
> unsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine-java?hl=en.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> > To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> > To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> > For more options, visit this group athttp://
> groups.google.com/group/google-appengine-java?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to