Jump to content

Posting a form?


aximbigfan

Recommended Posts

I have this:

 

(The reason for the \ is because this is being echoed through PHP)

 

function ajax()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject(\"Msxml2.XMLHTTP\");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
}
catch (e)
{
alert(\"AJAX must be supported!\");
return false;
}
}
}

xmlHttp.onreadystatechange=empty()
{
if(xmlHttp.readyState==4)
{
document.form.string.value=xmlHttp.responceText;
}
}
xmlHttp.open(\"POST\",\"index.php\",\"true\");
xmlHttp.send(null);
}

 

And I have a form (called "form").

 

How can I post this entire form with ajax?

 

Thanks,

Chris

Link to comment
https://forums.phpfreaks.com/topic/96619-posting-a-form/
Share on other sites

hi,

 

Lot of mistakes in the code.....

 

var xmlHttp; ................define this above everything i.e in global space of your javascript

 

the do

xmlHttp=ajax();

 

 

xmlHttp.open("POST","index.php","true");

xmlHttp.send(null);

 

when you do POST xmlHttp.send(null); is wrong you have to send the parameters too.

i.e

 

parameter="name=priti";

xmlHttp.send(parameter);

 

now when you have a form i.e form in javascript run the loop to all form element and create a parameter string and pass in send() function.

 

Regards

Link to comment
https://forums.phpfreaks.com/topic/96619-posting-a-form/#findComment-494613
Share on other sites

Ok, here is a new, less junky version. Although, it still does not work...

 

function ajax()
{
var xmlhttp;

try
{
xmlhttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlhttp=new ActiveXObject(\"Msxml2.XMLHTTP\");
}
catch (e)
{
try
{
xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");
}
catch (e)
{
alert(\"No AJAX support!\");
return false;
}

}
}
return xmlhttp;
}

var http = ajax();
var url = \"index.php\";
var params = \"mode=rot13&string=test\";

function handler()
{
if (http.readystate==4 && http.status==200)
{
document.form.string.value = http.responceText;
}
}

function post()
{
http.open(\"POST\", \"index.php\", true);

http.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");
http.setRequestHeader(\"Content-length\", params.length);
http.setRequestHeader(\"Connection\", \"close\");

http.onreadystatechange = handler;
http.send(params);
}

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/96619-posting-a-form/#findComment-494914
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

try this........

 

function ajax()

{

var xmlhttp;

 

try

{

xmlhttp=new XMLHttpRequest();

}

catch (e)

{

try

{

xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');

}

catch (e)

{

try

{

xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');

}

catch (e)

{

alert('No AJAX support!');

return false;

}

 

}

}

return xmlhttp;

}

 

var http = ajax();

var url ='index.php';

var params = 'mode=rot13&string=test';

 

function handler()

{

if (http.readystate==4 && http.status==200)

{

document.form.string.value = http.responseText;

}

}

 

function post()

{

http.open('POST', 'index.php', true);

 

http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

http.setRequestHeader('Content-length', params.length);

http.setRequestHeader('Connection', 'close');

 

http.onreadystatechange = handler;

http.send(params);

}

Link to comment
https://forums.phpfreaks.com/topic/96619-posting-a-form/#findComment-521030
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.