phpmady Posted July 7, 2010 Share Posted July 7, 2010 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 https://forums.phpfreaks.com/topic/206983-problem-in-more-than-one-ajax-call-from-a-page/ Share on other sites More sharing options...
radar Posted July 12, 2010 Share Posted July 12, 2010 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 https://forums.phpfreaks.com/topic/206983-problem-in-more-than-one-ajax-call-from-a-page/#findComment-1085084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.