Forum Moderators: open

Message Too Old, No Replies

Posting information without an actual form.

Possible with Javascript (Post instead of Get)?

         

Duskrider

8:34 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



I've been working on updating the company internal IT Wiki (UseMod), and one of the things everyone really wanted was a GUI for editing entries. I managed to find a nice javascript GUI and hack it up enough to get it to work, but in order to get the information entered into the GUI into the Wiki itself, I need to send it to the Wiki script.

The GUI itself is all javascript, and quite frankly above my head. I've edited it enough to get it to work with our Wiki, but the problem I'm running into is that I've had to send the text inside the GUI to the script via GET (in the URL), because I couldn't find a way in Javascript to do it with a Post... not having an actual form to reference. This works spectacularly in FireFox, but alas Internet Explorer chokes on the big URIs that come with a long Wiki entry.

Is there a way to send POST header information via Javascript without doing something like "document.myform.myfield.value='mytext'"?

The way I've got it set up I'm not submitting a form... simply sending the information to a URI once the Save button has been hit. We're a small group so it's really not a big deal doing that way, but I'm scratching my head trying to figure out how to get a variable to POST without a form or a submit.

daveVk

1:48 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do this via AJAX, XMLHttpRequest in particular. What is the problem with using a form, much simpler?

vincevincevince

1:53 am on Sep 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add yourself this to your HTML on the saving bit of the GUI:

<form id="myform" style="display:none" action="yourwiki.script">
<input id="mytext" name="mytext">
<input type="submit">
</form>

Now, your GET requesting code should be rewritten as:

document.getElementById('mytext').value=mytext; document.getElementById('myform').submit();

Basically, you have a hidden form, in which you set a form field to a given value, and then submit.