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
https://forums.phpfreaks.com/topic/101905-posting-ajax/
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
https://forums.phpfreaks.com/topic/101905-posting-ajax/#findComment-524679
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.