Topic: Submit Form
I'm trying to create an AJAX function that submits a form. So far, what I have it doing, is compiling all the form data into a string and submitting that. However, I think its maxing out the querystring.
Is there a way to submit the entire form through AJAX without sending it through the querystring?
//Global variables
var http = null;
//Create request
function ajaxCreateRequestObject() {
//Basic variable
var req;
//Check for browser compatibility
//Firefox, safari, opera...
if(window.XMLHttpRequest)
req = new XMLHttpRequest();
//IE v5+
else if(window.ActiveXObject)
req = new ActiveXObject("Microsoft.XMLHTTP");
//No compatibility
else
alert('Problem creating the XMLHttpRequest object.');
//Return the function
return req;
}
//Send request
function ajaxSendRequest(method, url, handler, parameters)
{
//Open up and send request
http.open(method, url, true);
http.onreadystatechange = handler;
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.send(parameters);
}
function adminProfileNewSubmit()
{
//Get the form elements
var Title=document.getElementById('adminFormProfileNewTitle').value;
var Body=document.getElementById('adminFormProfileNewDesc').value;
var Annc=document.getElementById('adminFormProfileNewAnn').value;
var Url=document.getElementById('adminFormProfileNewUrl').value;
var Guest=document.getElementById('adminFormProfileNewGuest').value;
var User=document.getElementById('adminFormProfileNewUser').value;
var Skin=document.getElementById('adminFormProfileNewSkin').value;
var Def=document.getElementById('adminFormProfileNewDefault').value;
//Validate form
statusbarUpdate('Validatin...',true);
if(adminProfileFormVerify() == false)
{
//Update status
statusbarUpdate('Submitting...',true);
//Prepare parameters
var data = 'Title='+escape(Title)+'&Body='+escape(Body)+'&Annc='+escape(Annc)+'&Url='+escape(Url)+'&Guest='+Guest+'User='+User+'&Skin='+escape(Skin)+'&Default='+Def+'';
var buttons = new Array( ['Okay', 'modalDeactivate()', 'modalBoxButtonYes'] );
modalInitiate('AdminResults', 'Success!', data, buttons, 300);
//Create and send request
http = ajaxCreateRequestObject();
ajaxSendRequest('POST','AJAX/adminBoard.asp?Action=3', adminProfileNewSubmitHandler, data);
}else
statusbarHide();
}
function adminProfileNewSubmitHandler()
{
//Finished request
if(http.readyState == 4 && http.status == 200)
{
//Get response text
var response = http.responseText;
//Check for success
if(response.indexOf('1')!=-1)
{
//Update content
adminContentShowpage('adminBoard.asp','1')
//Alert user to success
var buttons = new Array( ['Okay', 'modalDeactivate()', 'modalBoxButtonYes'] );
modalInitiate('AdminResults', 'Success!', 'The new profile has been created successfully.', buttons, 300);
}else
{
//Alert
var buttons = new Array( ['Okay', 'modalDeactivate()', 'modalBoxButtonYes'] );
modalInitiate('AdminResults', 'Error!', 'There was an unknown error creating new profile.', buttons, 300);
}
//Hide statusbar
statusbarUpdate('Loading...',false);
}else if(http.readyState == 4 && http.status != 200)
statusbarUpdate('Error with remote page.', true);
}
Anybody have any ideas? I'd really appreciate the help.