954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

xmlHTTP respnse

how can we sent multiple values in xmlHTTP respnse,
var xmlHttp
function <strong>callAjax(id)</strong> {
if (id.length==0) {
document.getElementById("txtHint").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {

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

i want to add "id2" variable also likecallAjax(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

servis
Junior Poster in Training
82 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

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

ShawnCplus
Code Monkey
Team Colleague
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
 

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";	
	}
}
R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

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

servis
Junior Poster in Training
82 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

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.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You