LemonInflux Posted April 19, 2008 Share Posted April 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
atl_andy Posted April 23, 2008 Share Posted April 23, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.