Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Usability

  • Print
  • + Share This
Like this article? We recommend

GET and POST with AJAX

To POST the request, we first need to create the request object. If you don’t have prior experience creating the request object, read my article "How To Use AJAX" or simply study the sample source code. Once the request object is created, call the sendFeed method and pass the URL that was created by the form:

function sendFeed(url)
{
 post.onreadystatechange = sendRequest;
 post.open("POST", url, true);
 post.send(url);
}

Once the response from the PHP object is received and properly loaded, make another request on the local file with which it responded. In this case, post.responseText provides us with the path to the new file:

function sendRequest()
{
 if(checkReadyState(post))
 {
  request = createRequestObject();
  request.onreadystatechange = onResponse;
  request.open("GET", post.responseText, true);
  request.send(null);
 }
}
  • + Share This
  • 🔖 Save To Your Account