javascript ajax php display -
by using javascript ajax have passed values php page... display values after retrieving database , print in ajax page...it displaying in alert page...but need display in ajax page....
ajax coding
<script> function optionsalert() { alert("call"); var xmlhttp; var qw=document.getelementbyid('c').value; var qw1=document.getelementbyid('c1').value; var qw2=document.getelementbyid('unit33').value; var qw3=document.getelementbyid('dept').value; var qw4=document.getelementbyid('class').value; alert(qw); alert(qw1); alert(qw2); alert(qw3); alert(qw4); if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { alert(xmlhttp.responsetext); if(xmlhttp.responsetext==1){ alert("name exists" ); return false; } else if(xmlhttp.responsetext==0) { alert("name available"); document.login.submit(); } } } var querystring = "?q=" + qw + "&q1=" + qw1 + "&q2=" + qw2 + "&q3=" + qw3 + "&q4=" + qw4; xmlhttp.open("get",'ques.php' + querystring,true); xmlhttp.send(); } php page
<?php include('connection.php'); if(($_get['q']!='') && ($_get['q1']!='') && ($_get['q2']!='') && ($_get['q3']!='') && ($_get['q4']!='')) { $a= mysql_query("select * unit1 unit='".$_get['q']."' , stopic='".$_get['q1']."' , qtype='".$_get['q2']."' , dept='".$_get['q3']."' , class='".$_get['q4']."'"); //$a= mysql_query("select * unit1 unit='unit1' , stopic='subtopic1' , qtype='normal questions'"); if(mysql_num_rows($a)>0) { while($row=mysql_fetch_array($a)) { $a1=$row['qno']; $a2=$row['ques']; $a3=$row['ch1']; $a4=$row['ch2']; $a5=$row['ch3']; $a6=$row['ch4']; $a7=$row['ans']; echo $a1."<br>";echo $a2."<br>";echo $a3."<br>";echo $a4."<br>";echo $a5."<br>";echo $a6."<br>";echo $a7."<br>"; echo 1; } } else { echo 0; } } ?>
below ajax coding create div element id
in ajax method
if(xmlhttp.responsetext==1){ document.getelementbyid("id").innerhtml = "name exists"; return false; } else if(xmlhttp.responsetext==0) { document.getelementbyid("id").innerhtml="name available"; document.login.submit(); } "id" own div id
Comments
Post a Comment