how can we sent multiple values in xmlHTTP respnse,

var xmlHttp
function [B]callAjax(id)[/B] {
if (id.length==0) {
document.getElementById("txtHint").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {

& so on....................
................................

i want to add "id2" variable also like callAjax(id,id2)
how can we do it??????

secondly, how can we intiame the user at completion that the request has been completed well.

please help in this regard

shuja

I'm not quite sure what you want to accomplish, and I'm also note sure what the word intiame means, Google doesn't either. You can send as many request parameters as you like given the HTML protocol

This is how I usually do it. Below you will find my main ajax object and then two different functions, one for get and one for post.

//the ajax object for all ajax functions
function ajaxObject()
{
	var objectsuccess = true;
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				objectsuccess = false;
			}
		}
	}
	
	if(objectsuccess == false)
	{
		alert("Your browser does not support AJAX!");
		return false;
	}
	else
	{
		return xmlHttp;
	}
}

GET

//ajax main body function
function displayBody(bodypage, bodyvar, bodyidpkvar, bodydatesid, adddep)
{
	var xmlHttp = ajaxObject();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var schResults = document.getElementById("maincontent");
			schResults.innerHTML = xmlHttp.responseText;
		}
	}
	
	var urlstring = "";
	if(bodyvar != 0)
	{
		urlstring = "&id=" + bodyvar + "&idpk=" + bodyidpkvar + "&datespk=" + bodydatesid + adddep;
	}
	else if(adddep == "&addnew=true" || adddep == "&addid=true")
	{
		urlstring = adddep;
	}
	
	xmlHttp.open("GET","ajax_body.php?page=" + bodypage + urlstring,true);
	xmlHttp.send(null);
}

POST

//ajax function to save note and post result to the user
function saveNote()
{
	var notefrmid = document.getElementById('txtNotes');
	var useridfrmid = document.getElementById('hdnuserid');
	var enrolldatespkid = document.getElementById('hdnenrolldatespk');
	var noteResponseid = document.getElementById('noteResponse');
	
	var note = notefrmid.value;
	var userid = useridfrmid.value;
	var enrolldatespk = enrolldatespkid.value;
	
	if(note != "" && userid != "" && enrolldatespk != "")
	{
		var xmlHttp = ajaxObject();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				var responsestring = xmlHttp.responseText;
				var response = "";
				if(responsestring.indexOf("error") == -1)
				{
					response = "Success";
					notefrmid.value = "";
				}
				else
				{
					response = "Error";
					//response = responsestring; //for development
				}
				noteResponseid.innerHTML = response;
			}
		}
		
		xmlHttp.open("POST","ajax_writenote.php",true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlHttp.send("note=" + note + "&id=" + userid + "&enrolldatespk=" + enrolldatespk);
	}
	else
	{
		noteResponseid.innerHTML = "Enter Note";	
	}
}

thank you for your great help, please can you guide me how can we display message conditionly after completion of the task.

thanks in advance

regards,

shuja

thank you for your great help, please can you guide me how can we display message conditionly after completion of the task.

thanks in advance

regards,

shuja

Breaking down the "POST" section of my script
first at line 15 I generate the ajax object
second at line 36 I define the script I am going to post to and open a connection to it
third at line 37 I define the type of data that will be transfered, required for posting with ajax
fourth at line 38 I define and send the query string minus the initial "?"

line 16 is a function that senses the changes in the xmlHttp object state and the if statement determines if the status is successful or complete, xmlHttp.readyState==4 is what you are looking for.

line 20 stores the xmlHttp.responseText data, which is just the output of the script that you just posted to, from that point you can do what ever you want to with it.

That's it, the rest of the stuff in that function was specific to my application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.