Jump to content

Posting AJAX


LemonInflux

Recommended Posts

Hello. Something's been irritating me for a while, and I can't think how to do it.

 

Up until now, my knowledge of AJAX has been using a URL to send/receive data.

 

However, if I'm not mistaken, URLs can only be 255 characters.

 

So, If I'm posting a form with 2 text fields and a textarea, how do I pass 3 variables which together could potentially have 10,000 characters or more? Is this still done through the URL?

 

Thanks in advance,

Tom

Link to comment
Share on other sites

How far along on this are you?  I am learning this currently as well, and here's the basics of what I know so far.  This assumes you have some basic ajax knowledge, like creating XHR and such.

 

you'll have your form, this example uses a text area with a submit button that calls a js function:

<form id="form">
<textarea id="text" rows="6" cols="50" name="text"></textarea>
<input type="button" value="value" onClick="submitText();" />
</form>

 

for submitText(), you'll need to assign the textarea to a variable and send that using post.

function submitText() {
   var text = document.getElementById("text").value;   // if you need another variable, use:  var nextText = document.getElementById("nextText").value;
   var url = process.php;          // whatever script you use to process

   request.open("POST", url, true);
   request.onreadystatechange= submitConfirmation;         // whatever confirmation you show the user
   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   request.send("text=" + escape(text));        // if you add more variables, use:  + "&nextText=" + escapte(nextText)
}

 

That's about all I know so far.  The key to this is the setRequestHeader, which tells the server the data is like it was included in a url using GET.  That should at least get you started in the right direction.  Hope it helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.