In the future, please post a complete minimal test case. This will aid those trying to help you by not making them have to perform busywork to answer your questions. Furthermore, in producing a minimal test case you will often discover the error yourself.

Originally Posted by
wizkid
i was trying to make two separate ajax request on one page
www.phoenix.exofire.net/events.php
i have two js written for it. when only one of the js are inserted it works fine , however when i insert both th js into my code one of the request doesnt take place.
Code:
//login.js
var xmlHttp;
var status;
status=check_status();
Globals are evil. Note how you had to take care when naming the variable (xmlHttp1) holding the response for event_details.php. Use closures and objects. Also, pick more descriptive names, such as "loginResponse". Would you know exactly what the variable "xmlHttp" was supposed to hold without looking at every assignment statement for it?

Originally Posted by
wizkid
Code:
function stateChanged1()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
// document.getElementById("showstatus").innerHTML=xmlHttp.responseText ;
status=xmlHttp.responseText;
//alert(status);
select_content(status);
}
Function stateChanged1() is missing closing bracket. This will prevent login.js from being properly processed and check_status() from being defined. (moral: check your error console).

Originally Posted by
wizkid
Code:
<script type="text/javascript">
...
function load_event (event_name)
...
function stateChanged1()
{
if (xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete")
document.getElementById("events").innerHTML=xmlHttp1.responseText;
alert("THIS IS THE response : \n "+xmlHttp1.responseText);
}
</script>
login.js also defines stateChanged1(). Whichever definition is evaluated last will override the other. This collision is the same you face with global variables and poor naming. Closures will again solve the problem. Example:
Code:
function load_event (event_name) {
var eventDescriptionResponse=GetXmlHttpObject();
function stateChanged() {
if (eventDescriptionResponse.readyState==4 || eventDescriptionResponse.readyState=="complete")
document.getElementById("events").innerHTML=eventDescriptionResponse.responseText;
//alert("THIS IS THE response : \n "+eventDescriptionResponse.responseText);
}
if (eventDescriptionResponse==null) {
alert ("Browser does not support HTTP Request");
return;
}
var url="event_details.php";
var param="eventname="+event_name;
eventDescriptionResponse.onreadystatechange=stateChanged;
eventDescriptionResponse.open('POST',url,true);
eventDescriptionResponse.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
eventDescriptionResponse.setRequestHeader("Content-Length" , param.length);
eventDescriptionResponse.setRequestHeader("connection", "close");
eventDescriptionResponse.send(param);
}
As eventDescriptionResponse is never seen outside of load_event, you could give it a less descriptive name (e.g. "response"). In this case, the scope the variable appears in obviates any ambiguity as to the variable's purpose.
Better example:
Code:
function postRequest(url, param, handleResponse) {
var request = xmlHttp=GetXmlHttpObject();
if (null != request) {
request.open('POST',url,true);
request.onreadystatechange=function() {
switch (request.readyState) {
case 1:
case 2:
case 3:
break;
case 4:
case "complete":
handleResponse(request);
break;
}
};
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-Length" , param.length);
request.setRequestHeader("connection", "close");
request.send(param);
}
return request;
}
function check_status() {
var param="foo=bar&bam=bug-AWWK!";
// fill param
var request = postRequest("check_status.php", param,
function (request) {
select_content(request.responseText);
}
);
if (! request) {
//alert ("Browser does not support HTTP Request");
}
}
function load_event (event_name) {
var param="eventname="+event_name;
// fill param
var request = postRequest("event_details.php", param,
function (request) {
document.getElementById("events").innerHTML=eventDescriptionResponse.responseText;
}
);
if (! request) {
//alert ("Browser does not support HTTP Request");
}
}
Best example: use a JS lib, such as Prototype, jQuery, MooTools or YUI, which all provide more powerful and more complete handling of cross browser issues and errors than the above code.