Вопрос

I'm using fastcgi++ for my ajax pages, parsing and encoding with json-spirit. (I'm also very new to c++)

I'm having trouble figuring out how to access the post data.

I cut my teeth on .net & php, and those would conveniently convert a json data string (speaking in jQuery here, so my vocab is probably off) to simple variables or $_POST array respectively.

I'm looking at the main example for reading POST data on fastcgi++ http://www.nongnu.org/fastcgipp/doc/2.1/a00003.html, but it only shows it->first and it->second.value. I can't find anything in the linked docs on that page.

Since I don't have the http knowledge to articulate this properly, is there a way to read a jQuery ajax() data string, for example, {foo: "bar", jim: "bob"} by foo and jim in fastcgi++?

If not, should the it->first simply be treated as a string to be parsed by json-spirit ?

Это было полезно?

Решение

Ah, OK.

First, jQuery http://api.jquery.com/jQuery.ajax/

data

Type: PlainObject or String

Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests.

So jQuery does break it up into a POST query string for you.

Then, fastcgi++, via the Session tutorial, there's a piece of code environment().findPost("data").value that apparently references the element <input type='text' name='data' value='Hola señor, usted me almacenó en una sesión' />. No need to use spirit to parse incoming ajax data.

environment() looks like it's initialized automatically for you in Fastcgipp::Request.

I'm loving this framework more each day!

Now, I just need to figure out how to integrate it with websocket++...


How a multi-level json object will be converted into a query string and read in via fastcgi++ is probably best left to another question.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top