简体   繁体   English

javascript ajax php显示

[英]javascript ajax php display

by using javascript ajax i have passed the values to php page... display the values after retrieving from database and print in ajax page...it displaying in alert page...but i need to display in ajax page.... 通过使用javascript ajax,我已将值传递给php页面...从数据库中检索后显示值并在ajax页面中打印...在警报页面中显示...但是我需要在ajax页面中显示...。

ajax coding Ajax编码

<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 for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for 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 already 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页面

<?php 
include('connection.php'); 
if(($_GET['q']!='') && ($_GET['q1']!='') && ($_GET['q2']!='') && ($_GET['q3']!='') && ($_GET['q4']!=''))
{
    $a= mysql_query("select * from unit1 where unit='".$_GET['q']."' and stopic='".$_GET['q1']."' and qtype='".$_GET['q2']."' and dept='".$_GET['q3']."' and class='".$_GET['q4']."'");
    //$a= mysql_query("select * from unit1 where unit='unit1' and stopic='Subtopic1' and 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 the ajax coding create div element with id 在ajax编码下面,创建具有id的div元素

in your ajax method 在你的ajax方法

if(xmlhttp.responseText==1){
                document.getElementById("id").innerHTML = "name already Exists";                   
                return false;   
                }        
               else if(xmlhttp.responseText==0)
               {
                document.getElementById("id").innerHTML="name available";
                document.login.submit();    
               }

"id" your own div id “ id”是您自己的div ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM