phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


AJAX - Remote Server: Connecting to Remote Server

Tag:    Category: PHP Application
post: 18 Mar 2008 read: 139


AJAX Remote Server Step By Step Tutorial - part 1: At previous post about AJAX Passing parameters, we still use same server. How if we call from 'real' server from internet? You just modify a little like this:


var serveraddress = "http://www.mysite.com/calc.php?";
var param1;
var param2;
var params;

function process(funcCalc)
{


  myDiv = document.getElementById("myDivElement");
  myDiv.innerHTML = "";
  
  // will be continued if xmlHttp isn't void
  if(!xmlHttp) return;

  if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4)
  {
    try
    {
	  param1 = document.getElementById("param1").value;
	  param2 = document.getElementById("param2").value;
	  
	  params = "param1=" + param1 + "¶m2=" + param2 + "&func=" + funcCalc;
	  
      xmlHttp.open("Get", serveraddress + params, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }
    catch(e)
    {
      alert("Can't connect to server\n" + e.toString());
    }
  }
  else
  // don't try to make server request if the XMLHttpObject is busy
  {
    alert("Can't connect to server, please try again later.");
  }
}




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting