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

 

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.