Jump to content

Submiting form using get


Recommended Posts

Hi,

 

Using:

 

<form name="record" method="get" onSubmit="AjaxRequest("main","./includes/billing.php?action=records");">

 

to the following javascript for ajax:

 

function AjaxRequest(target_div,file,check_div)
{
var MyHttpRequest = false;
var MyHttpLoading = '<table width="100%" border="0" bgcolor="#FFFFFF" height="209"><tr><td align="center" valign="middle"><img src="./loading.gif"></td></tr></table>';
var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead';

if(check_div)
{
var check_value = document.getElementById(check_div).value;
}
else
{
var check_value = '';
}



if(window.XMLHttpRequest)
{
try
{
MyHttpRequest = new XMLHttpRequest();
}
catch(e)
{
MyHttpRequest = false;
}
}
else if(window.ActiveXObject)
{
try
{
MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
MyHttpRequest = false;
}
}
}
else
{
MyHttpRequest = false;
}



if(MyHttpRequest)
{
var random = Math.random() * Date.parse(new Date());

var file_array = file.split('.');
if(file_array[1] == 'php')
{
  var query_string = '?rand=' + random;
}
else if(file_array[1] == 'htm' || file_array[1] == 'html')
{
  var query_string = '';
}
else
{
  var query_string = check_value + '&rand=' + random;
}


MyHttpRequest.open("get", url_encode(file + query_string), true);


MyHttpRequest.onreadystatechange = function ()
{
if(MyHttpRequest.readyState == 4)
{
document.getElementById(target_div).innerHTML = MyHttpRequest.responseText;
}
else
{
document.getElementById(target_div).innerHTML = MyHttpLoading;
}
}
MyHttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
MyHttpRequest.send(null);
}
else 
{
document.getElementById(target_div).innerHTML = ErrorMSG;
}
}

 

But it doesnt seem to work, how can I submit a form to it using GET method?

 

 

 

Thanks

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.