2014-01-29 2 views
0

Я написал код ниже; когда я выбираю India/America в связанном раскрывающихся текстовых файлах с некоторым содержанием, должно быть считываться и отображаться внутри div элемента, но я получаю сообщение об ошибке в строке xhr.send()Выпадающая страница с использованием Ajax

может кто-нибудь объяснить, почему ??

<html> 
<head> 
<script> 
function getcity() 
{ 
    var a=document.getElementById("country"); 
    var b=a[a.selectedIndex].value; 
    alert(b); 
    var xhr=new XMLHttpRequest(); 
    if(b=="India") 
    { 
     xhr.onreadystatechange=function() 
     { 
      if((xhr.readystate==4)&&(xhr.status==200||xhr.status==304)) 
      { 
       document.getElementByID("display").innerHTML=xhr.responseText; 
      } 
     } 
     xhr.open("GET","india.txt",true); 
    } 
    else 
    { 
     xhr.onreadystatechange=function() 
     { 
      if((xhr.readystate==4)&&(xhr.status==200||xhr.status==304)) 
      { 
       document.getElementByID("display").innerHTML=xhr.responseText; 
      } 
     } 
     xhr.open("GET","america.txt",true); 
    } 
    xhr.send(null); 
} 
</script> 
</head> 
<body> 
<select id="country" onchange="getcity()"> 
<option>India</option> 
<option>America</option> 
</select> 
<div id="display"></div> 
</body> 
</html> 
+0

Удалить 'null' из xhr.send (нуль); –

+0

Я пробовал Rajesh ... Тем не менее, он не отображает содержимое в текстовом файле ... содержимое просто равно String – user3094600

+0

Удалить xhr.status == 304 –

ответ

0
<html> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

<script> 
function getcity() 
{ 
    var a=document.getElementById("country"); 
    var b=a[a.selectedIndex].value; 
    alert(b); 
    var xhr=new XMLHttpRequest(); 
    if(b=="India") 
    { 
     xhr.onreadystatechange=function() 
     { 
      if((xhr.readystate==4)&&(xhr.status==200||xhr.status==304)) 
      { 
       document.getElementByID("display").innerHTML=xhr.responseText; 
      } 
     } 
     xhr.open("GET","india.txt",true); 
    } 
    else 
    { 
     xhr.onreadystatechange=function() 
     { 
      if((xhr.readystate==4)&&(xhr.status==200||xhr.status==304)) 
      { 
       document.getElementByID("display").innerHTML=xhr.responseText; 
      } 
     } 
     xhr.open("GET","america.txt",true); 
    } 
    xhr.send(null); 
} 
</script> 
</head> 
<body> 
<select id="country" onchange="getcity()"> 
<option>India</option> 
<option>America</option> 
</select> 
<div id="display"></div> 
</body> 
</html> 
+0

Но как получилось, что я не получаю выход ... мне нужно сделать любой порт confi ???? конфигураций – user3094600

+0

am using notepad ++ – user3094600

+0

ya .. вам нужно будет запустить этот код в localhost –

Смежные вопросы