Jump to content

problem in more than one ajax call from a page


phpmady

Recommended Posts

Hi,

 

I try to access a ajax call more than a tim, but its giving a problem.

 

 

 

2 times am using ajax in my page

 

1. one for country, city list [  onChange = getCity(this.value); ]

2. Sections, Sub-sections list [ onChange = getSubSection(this.value); ]

 

am using 2 js page one for city and section

 

Here the js for section

 

// JavaScript Document

 

 

 

 

 

 

 

 

 

 

 

var xmlhttp;

 

//function namechange(name_fieldvalue)

 

 

 

function getSection(sid)

 

{

 

alert(sid);

 

/*

 

alert(name_fieldvalue);

 

alert(name_fieldname);

 

alert(id_val);

 

alert(id_fieldname);

 

alert(table_name);

 

*/

 

alert(document.getElementById("fat").innerHTML);

 

if (sid.length==0)

 

  {

 

  document.getElementById("fat").innerHTML="";

 

  return;

 

  }

 

xmlhttp=GetXmlHttpObject();

 

if (xmlhttp==null)

 

  {

 

  alert ("Your browser does not support XMLHTTP!");

 

  return;

 

  }

 

var url="find_sub_section.php";

 

url=url+"?sid="+sid;

 

 

alert(url);

 

 

 

xmlhttp.onreadystatechange=stateChanged;

 

xmlhttp.open("GET",url,true);

 

xmlhttp.send(null);

 

}

 

 

 

function stateChanged()

 

{

 

alert("sdafsad");

 

if (xmlhttp.readyState==4)

 

  {

 

alert(xmlhttp.responseText);

 

  document.getElementById("fat").innerHTML=xmlhttp.responseText;

 

  }

 

}

 

 

 

function GetXmlHttpObject()

 

{

 

if (window.XMLHttpRequest)

 

  {

 

  // code for IE7+, Firefox, Chrome, Opera, Safari

 

  return new XMLHttpRequest();

 

  }

 

if (window.ActiveXObject)

 

  {

 

  // code for IE6, IE5

 

  return new ActiveXObject("Microsoft.XMLHTTP");

 

  }

 

return null;

 

}

 

 

 

 

 

 

This for city

 

 

 

var xmlhttp;

 

//function namechange(name_fieldvalue)

 

 

 

function getCity(cid)

 

{

 

 

 

//alert(cid);

 

/*

 

alert(name_fieldvalue);

 

alert(name_fieldname);

 

alert(id_val);

 

alert(id_fieldname);

 

alert(table_name);

 

*/

 

 

 

if (cid.length==0)

 

  {

 

  document.getElementById("city_id").innerHTML="";

 

  return;

 

  }

 

xmlhttp=GetXmlHttpObject();

 

if (xmlhttp==null)

 

  {

 

  alert ("Your browser does not support XMLHTTP!");

 

  return;

 

  }

 

var url="findcity.php";

 

url=url+"?cid="+cid;

 

 

 

xmlhttp.onreadystatechange=stateChanged;

 

xmlhttp.open("GET",url,true);

 

xmlhttp.send(null);

 

}

 

 

 

function stateChanged()

 

{

 

if (xmlhttp.readyState==4)

 

  {

 

  document.getElementById("city_id").innerHTML=xmlhttp.responseText;

 

  }

 

}

 

 

 

function GetXmlHttpObject()

 

{

 

if (window.XMLHttpRequest)

 

  {

 

  // code for IE7+, Firefox, Chrome, Opera, Safari

 

  return new XMLHttpRequest();

 

  }

 

if (window.ActiveXObject)

 

  {

 

  // code for IE6, IE5

 

  return new ActiveXObject("Microsoft.XMLHTTP");

 

  }

 

return null;

 

}

 

 

 

 

 

 

 

If i change the section , automatically city is changing...

 

How to solve this problem

 

Thank You

 

 

 

 

 

 

This could be a shot in the dark, but this function is in both versions of the javascript:

 

function stateChanged()

 

{

 

if (xmlhttp.readyState==4)

 

  {

 

  document.getElementById("city_id").innerHTML=xmlhttp.responseText;

 

  }

 

}

 

 

only difference is, one changes city_id and the other changes fat...  so rename one, and see if that fixes your issue.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.