Mixing Get and Post
April 6, 2005
Over the past several days, I’ve been working on an in-page contact form that uses sajax (not that it really needs it, but mostly to play around with it, and get familiar with this sort of stuff) and I came upon whats most likely a rather common occurence. Theres a verify function that only needs to send short strings back and forth, and then a submit function which sends all of the fields (and in theory is much closer to bumping into the character limit for GET); in short I want to use both GET and POST for different functions in the same page.
The nifty part is, I was able to hack it together and make it work which, as always, is an exciting feeling.
(and as an aside, its a wee bit past 0500 right now, so I’m going to worry about posting the full code and explanation tomorrow (and probably to the sajax forum, and a link/copy over here) so I’ll just go with the short description for now…… oh, that and I just thought of something else I want to add to it
)
Starting off with the export (I’m working all this in PHP, btw):
sajax_export("parse");
sajax_export(array("send", 'POST'));
In sajax.php I’ve left the default request type as GET, so when called without the extra, nested parameter, thats what it uses. But when you export a function with a specified request type, it switches the request type in the output js. Using the specified, or default, request type I create a parallel array of request types to match the export list. Then, when exporting the stubs, I use this second array to let each function specify what it wants to use (and the idea I just had, stems from the GET/POST discussion on the sajax forum, and should allow you to specify at run-time which request you want to use).
And just to throw everything on the table, I’m sure most of you saw this, but the reason I went with the slightly odd nested array parameter was to maintain backwards compatability with code written for 0.10 and before (that and I wasn’t feeling to inclined to rewrite the whole shebang). I have no doubt this could be rewritten many different ways (and probably will be rewritten by somebody wiser and more experienced), but it seems to do the trick for now.
As I said, I’ll post the code tomorrow or thursday at the latest, but hopefully this will serve as a bit of a preview in the mean time.




[...] ing news: BetBug.com - new P2p gambling. Wacky. Wonder how it works… Kevin Pratt: Mixing Get and Post on Ajax blog: Over the past several da [...]
[...] ing news: BetBug.com - new P2p gambling. Wacky. Wonder how it works… Kevin Pratt: Mixing Get and Post on Ajax blog: Over the past several da [...]
Internet 800 Directory - Directory of free toll free, 800, 888, 877, and 866 listings of businesses by company, number and type of industry, regardless of long distance carrier. Yellow page advertising, Web 888 pages and banners available.
888
I would have to say if that were my situation I would also agree, but it is not my current situation. The last post leading up to this one would be the same answer in my humble opinion. Great site and keep the nice content coming
Hypnosis: How Hypnosis Helps You Quit Smoking?…
The word hypnosis may frighten you to some extent, but it can’t be more than the fright of the cigarette calamity….