iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning AJAX Course: Ajax: Get and Post - www.itechcollege.com AJAX Course: Ajax: Get and Post - www.itechcollege.com
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

courses > AJAX > Ajax: Get and Post

AJAX: Get and Post

There are two methods for requesting data:

  • Get
  • Post

To use "Get":

httpRequest.open('GET', url, true);
httpRequest.send('');

To use "Post":

httpRequest.open("POST", url, true);
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.setRequestHeader("Content-length", qst.length);
httpRequest.setRequestHeader("Connection", "close");
httpRequest.send(qst);

Let's modify the function "getFile()" in the example of the previous chapter:

For using "Get":

function getFile(httpRequest,url,posTag){
if(!httpRequest){
alert('Error - Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = function(){
showContents(httpRequest,posTag);//function display contents
}

//send data to server
var email = document.getElementById('email').value;
var pass = document.getElementById('pass').value;
var qst = "?email=" + email + "&pass=" + pass;
//-----Get-----------
httpRequest.open("GET", url + qst, true);
httpRequest.send('');
//-----Get-----------
}

For using Post:

function getFile(httpRequest,url,posTag){
if(!httpRequest){
alert('Error - Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = function(){
showContents(httpRequest,posTag);//function display contents
}

//send data to server
var email = document.getElementById('email').value;
var pass = document.getElementById('pass').value;
var qst = "email=" + email + "&pass=" + pass;
//-----post----------
httpRequest.open("POST", url, true);
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.setRequestHeader("Content-length", qst.length);
httpRequest.setRequestHeader("Connection", "close");
httpRequest.send(qst);
//-----post----------
}

As you can see, they are just slightly different.



  Back to Index Page
 Next Page:  

AJAX Introduction
AJAX Basic
AJAX Display Contents
AJAX Get and Post
AJAX and Database
AJAX and XML
AJAX Dynamically Update Data


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech