gilgalbiblewhee 10-24-2008, 12:18 AM function getit(aid, aurl){
var req = createRequest();
if(req){
req.onreadystatechange = function(){
var c = document.getElementById(aid);
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
c.innerHTML = req.responseText;
}
}
}
}
req.open('GET', aurl, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}
function bodyOnload(){
fillLog1();
fillLog2();
fillLog3();
fillLog4();
fillLog5();
}
function fillLog1(){
getit('game_login_0','login.php?game=game1');
}
function fillLog2(){
getit('game_login_1','login.php?game=game2');
}
function fillLog3(){
getit('game_login_2','login.php?game=game3');
}
function fillLog4(){
getit('game_login_3','login.php?game=game4');
}
function fillLog5(){
getit('game_login_4','login.php?game=game5');
}
How would this work in POST method?
shyam 10-24-2008, 06:23 PM function getit(aid, aurl){
var req = createRequest();
if(req){
...
}
req.open('GET', aurl, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
}
}
How would this work in POST method?
by changing GET to POST
gilgalbiblewhee 10-24-2008, 11:12 PM by changing GET to POST
Never realized that!
What I mean is, if I have a form with fields then the url is used for the GET method by AJAX like this:
login.php?game=game1
But how different is POST?
it's going to be written :
login.php
right?
If so, how a I going to get game=game1?
carlitos_way 10-25-2008, 01:47 AM Never realized that!
What I mean is, if I have a form with fields then the url is used for the GET method by AJAX like this:
login.php?game=game1
But how different is POST?
it's going to be written :
login.php
right?
If so, how a I going to get game=game1?
Primarily, you should divide the url from the parameters:
url = "login.php";
parameters = "?game=game1";
Then you can use POST this way
req.open('POST', url, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(parameters);
}
this way the parameters are sent in the body of the request and are hidden from the view in the url
gilgalbiblewhee 10-25-2008, 05:52 AM Primarily, you should divide the url from the parameters:
url = "login.php";
parameters = "?game=game1";
Then you can use POST this way
req.open('POST', url, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(parameters);
}
this way the parameters are sent in the body of the request and are hidden from the view in the url
Ok. Thanks. First time I'm using POST.
A1ien51 10-27-2008, 02:39 PM gilgalbiblewhee example is not 100% correct since it should not have a ? in the post.
You also should be setting these headers when you are going to be making a post:
req.open('POST', url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = fooCallback;
req.send(params);
Eric
gilgalbiblewhee 10-28-2008, 10:09 PM gilgalbiblewhee example is not 100% correct since it should not have a ? in the post.
You also should be setting these headers when you are going to be making a post:
req.open('POST', url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = fooCallback;
req.send(params);
Eric
Like this?
// JavaScript Document
function createRequest(){
var req = false;
try {
req = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e2) {
try {
req = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e3) {
try {
req = new XMLHttpRequest();
} catch (e1) {
req = false;
}
}
}
return req;
}
function getit(aid, aurl){
var req = createRequest();
if(req){
req.onreadystatechange = function(){
var c = document.getElementById(aid);
if(req.readyState){
if(req.readyState == 4){
if(req.status == 200){
c.innerHTML = req.responseText;
}
}
}
}
var params = "?game=" + document.getElementById('game_id').value;
/*
req.open('GET', aurl, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.send(null);
*/
//http://www.codingforums.com/showthread.php?p=743212#post743212
req.open('POST', aurl, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");
req.onreadystatechange = fooCallback;
req.send(params);
}
}
function bodyOnload(){
fillLog1();
fillLog2();
fillLog3();
fillLog4();
fillLog5();
}
function fillLog1(){
getit('game_login_0','login.php');
}
function fillLog2(){
getit('game_login_1','login.php');
}
function fillLog3(){
getit('game_login_2','login.php');
}
function fillLog4(){
getit('game_login_3','login.php');
}
function fillLog5(){
getit('game_login_4','login.php');
}
|
|