如何调用AJAX一个AJAX加载网页

如何调用AJAX一个AJAX加载网页

本文介绍了AJAX jquery相关: - 如何调用AJAX一个AJAX加载网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我打电话通过AJAX搜索。现在我想调用另一个AJAX将由AJAX被加载并可以编辑的页面上。

Assume I'm calling search through AJAX. Now I want to call another AJAX on the page that will be loaded by AJAX and can be edited.

<input type="button" id=sb value="Search Contacts" />

<input type="text" name="search" placeholder="search contacts" id="s1" style="display:none" />

<input type="text" id="b1" value="<?php echo $username ; ?>" style="display:none;float:left" />

我使用AJAX调用PHP文件。现在,我更想呼吁AJAX通过AJAX加载的数据。这可能吗?

I am using AJAX to call a php file. Now, I further want to call AJAX on the data loaded through AJAX. Is it possible?

我可以通过调用包含AJAX页面中的jQuery(AJAX)?请问这项工作?

Can I call an jquery (AJAX) containing page through AJAX? Will that work?

我创建的搜索框,并从通过AJAX数据库的显示结果,让我在表格的形式。现在,我想该表转换成直播表,该表上点击可以编辑和数据可存储。

I am creating search box and its displaying result from database through AJAX which gives me in the form of table. Now, I want to convert that table into live table which on click can be edited and data can be stored.

我知道如何创建直播表,但不知道如何调用搜索,以及在同一时间直播表。

I know how to create live table but don't know how to call search as well as live table at the same time.

推荐答案

我在此与分页我采用现场搜索应用程序的PHP页面

PHP page of my application in this live search with pagination i am applied

<html>
<head>
<script type="text/javascript">
//====================================================================================================================
//============================================first call when page load=============================================
    function ajaxCall(n)
    {
        //alert("display ajacCall ");
        //alert("page no ::"+n);

        var ajaxRequest;
        try
        {
                ajaxRequest = new XMLHttpRequest();
        }
        catch (e)
        {
                try
                {
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                         }
                    catch (e)
                    {
                            alert("Your browser broke!");
                            return false;
                    }
            }
        }
        ajaxRequest.onreadystatechange=function()
        {
                if(ajaxRequest.readyState==4)
                {
                        //alert("Response :: "+ajaxRequest.responseText);
                        document.getElementById("displayButton").innerHTML=ajaxRequest.responseText;
                        if(n!=0)
                        {
                            disp_Record(n);
                        }
                        else
                        {
                            disp_Record(0);
                        }
                }
        }

        var query="ajaxhendler.php?msg=select";
        //alert("Request ::" +query);
        ajaxRequest.open("POST",query,true);
        ajaxRequest.send();
    }
//================================================Display Recodr to button Press================================================
//================================================Display Record to Static Button===============================================
    function disp_Record(n)
    {
        //alert("display record function");
        var ajaxRequest;
        try
        {
                ajaxRequest = new XMLHttpRequest();
        }
        catch (e)
        {
                try
                {
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    catch (e)
                    {
                            alert("Your browser broke!");
                            return false;
                    }
            }
        }
        ajaxRequest.onreadystatechange=function()
        {
                if(ajaxRequest.readyState==4)
                {
                        //alert("Response :: "+ajaxRequest.responseText);
                        document.getElementById("displayRecord").innerHTML=ajaxRequest.responseText;
                }
        }

        //alert("txt::"+ txt)
        var query="ajaxhendler.php?msg=selectRecordNo&no_of_record="+n;
        //alert("Request ::" +query);
        ajaxRequest.open("POST",query,true);
        ajaxRequest.send();
    }

//==============================================For Live search==============================================================
//===========================================For live search Display Button=================================================
    function callSearch(n,text)
    {
        //alert("call Search First Function");
        var ajaxRequest;
        try
        {
                ajaxRequest = new XMLHttpRequest();
        }
        catch (e)
        {
                try
                {
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    catch (e)
                    {
                            alert("Your browser broke!");
                            return false;
                    }
            }
        }
        ajaxRequest.onreadystatechange=function()
        {
                if(ajaxRequest.readyState==4)
                {
                        //alert("Response :: "+ajaxRequest.responseText);
                        document.getElementById("displayButton").innerHTML=ajaxRequest.responseText;
                        if(n!=0)
                        {
                            disp_Record_live(n,text);
                        }
                        else
                        {
                            disp_Record_live(0,text);
                        }
                }
        }
        var txt=document.getElementById("txtsearch").value;
        //alert("txt::"+ txt)
        var query="ajaxhendler.php?msg=selectRecord&txt="+txt;
        //alert("Request ::" +query);
        ajaxRequest.open("POST",query,true);
        ajaxRequest.send();
    }

//====================================================================================================================
function disp_Record_live(n,text)
    {
        //alert("Display Record live Second Function");
        var ajaxRequest;
        try
        {
                ajaxRequest = new XMLHttpRequest();
        }
        catch (e)
        {
                try
                {
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                        try
                        {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                    catch (e)
                    {
                            alert("Your browser broke!");
                            return false;
                    }
            }
        }
        ajaxRequest.onreadystatechange=function()
        {
                if(ajaxRequest.readyState==4)
                {
                        //alert("Response :: "+ajaxRequest.responseText);
                        document.getElementById("displayRecord").innerHTML=ajaxRequest.responseText;
                }
        }

        var txt=document.getElementById("txtsearch").value;
        //alert("txt::"+ txt)
            var query="ajaxhendler.php?msg=select_Record_No_live&no_of_record_live="+n+"&findR="+txt;
        //alert("Request ::" +query);
        ajaxRequest.open("POST",query,true);
        ajaxRequest.send();
    }

</script>


</head>

<body onLoad="<?php if($_GET['txt']=="")
                    {
                        echo "ajaxCall(";
                        $n=0; if($_GET['page']!=null)
                            {
                                echo $_GET['page'];
                            }
                            else
                            {
                                echo $n;
                            }
                        echo ")";
                    }
                    else
                    {
                        echo "callSearch(";
                        echo $_GET['page'].",'".$_GET['txt']."')";
                    } ?>" onUnload="msg()" bgcolor="#CCCCCC">
        <form>
 <table width="100%">


  <tr bgcolor="#CCFFCC">
                                <td  colspan="5">
                                       <font color="#CC6666">Search Record By Name</font><input type="text" name="txtsearch" id="txtsearch" value="<?php echo $_GET['txt'];?>" onKeyUp="callSearch(<?php
                                       $n=0;
                                       if($_GET['page']!=null)
                                       {
                                        echo $_GET['page'].",'".$_GET['txt']."'";
                                        }
                                        else
                                        { echo $n;}

                                        ?> )"/>
                                </td>
                                <td align="right">
                                        <a href="insert.php">Insert Record</a>
                                </td>
                            </tr>
                </table>
                <table width="100%">
                             <tr>
                                    <td>
                                        <div id="displayRecord"></div>
                                    </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="displayButton">
                                    </div>
                                </td>
                            </tr>
                </table>

        </form>
</body>
</html>

这是我Handlerpage.php

and this is my Handlerpage.php

<?php
        $page_name = "http://localhost/desk.php";
        $msg=$_GET['msg'];
if($msg=='select')
        {

                load_pages($_GET['page']);
        }
        if($msg=="selectRecord")
        {
                live_search_pages();
        }
        if($msg=="selectRecordNo")
        {
            $n=$_GET['no_of_record'];
            disp_Record($n);
        }
        if($msg=="select_Record_No_live")
        {
            $n=$_GET['no_of_record_live'];
            live_search($n,$t);

        }

//==================================================================pages============================================
//=====================================================Static button================================================
function load_pages($page)
{
        $cn=mysql_connect("localhost","root","");
        mysql_select_db("per_info",$cn);
        $query="SELECT count(*) 'TR' from p_info";
        $rs = mysql_query($query);
        $rec = mysql_fetch_array($rs);
        $n=$rec['TR'];
        if($n>0)
        {
        $pages=ceil($n/3);

        $i=0;

        echo "<table align=\"center\"><tr><td align=\"right\" bgcolor=\"#666666\"><font color=\"#FFFFFF\">Pages : </td><td align=\"center\" bgcolor=\"#666666\">";
        while($i<$pages)
        {
                echo "<input type=\"button\" value=\"".($i+1).""; echo "\" onclick=\"disp_Record(".($i*3).")\" />";
                $i=$i+1;
        }
        echo "</td></tr></table>";
        }
        else
        {
            echo "No Record Found";
        }
}
//============================================Selected record Display By Button========================================
//==========================================Display Record for static Record==========================================
        function disp_Record($btn)
        {
                $cn=mysql_connect("localhost","root","");
                mysql_select_db("per_info",$cn);

                //$btn=1;

                    $query="SELECT u.p_id 'ID', u.p_name 'NAME', u.p_add 'ADDRESS', l1.loc_name 'CITY', l2.loc_name
                        'STATE',u.p_gen
                        'GENDER', u.p_photo 'PIC', u.p_phone 'PH'
                        FROM p_info u, tbl_state l1, tbl_state l2
                        WHERE u.p_city = l1.loc_id
                        AND l2.loc_id = l1.loc_parent ORDER BY u.p_id desc LIMIT ".$btn.", 3";

                    $rs = mysql_query($query);
                    echo "<table width=\"100%\" frame=\"hsides\" >
                            <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Name</font></th>
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Address</font></th>
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">City</font></th>
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">State</font></th>
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Gender</font></th>
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Photo</font></th>
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Phone No</font></th>
                                <th bgcolor=\"#666666\"></th>
                                <th bgcolor=\"#666666\"></th>";
                while($row=mysql_fetch_array($rs))
                {

                    echo "<tr>
                                <td>".$row['NAME']."</td>
                                <td>".$row['ADDRESS']."</td>
                                <td>".$row['CITY']."</td>
                                <td>".$row['STATE']."</td>
                                <td>";if($row['GENDER']=="1")
                                        {
                                                echo "Male";
                                        }
                                        else
                                        {
                                                echo "Female";
                                        }
                                echo "</td>
                                <td>
                                    <img src=\"".$row['PIC']."\" alt=\"Pulpit rock\" width=\"50\" height=\"50\" />
                                </td>";
                                echo "<td>".$row['PH']."</td>
                                <td><input type=\"button\" value=\"Edit\" onclick=\"getid(".$row['ID'].",".$btn.",'')\"/></td>
                                <td><input type=\"button\" value=\"Delete\" onclick=\"callDelete(".$row['ID'].",".$btn.",'')\"/></td>
                          </tr>";

                }


        }

//==========================================================Live search By Button=====================================

function live_search_pages()
{
        $txt=$_GET['txt'];
        $cn=mysql_connect("localhost","root","");
        mysql_select_db("per_info",$cn);
        $query="SELECT count(*) 'TR' from p_info where p_name like '".$txt."%'";
        $rs = mysql_query($query);

        $rec = mysql_fetch_array($rs);
        $n=$rec['TR'];
        if($n>0)
        {
            $pages=ceil($n/3);

            $i=0;

            echo "<table align=\"center\"><tr><td align=\"right\" bgcolor=\"#666666\"><font color=\"#FFFFFF\">Pages : </td><td align=\"center\" bgcolor=\"#666666\">";
            while($i<$pages)
            {
                    echo "<input type=\"button\" value=\"".($i+1).""; echo "\" onclick=\"disp_Record_live(".($i*3).")\" />";
                    $i=$i+1;
            }
            echo "<td></tr></table>";
            }
        else
        {
            echo "No record Found";
        }
}
//================================================================Live search==========================================
        function live_search($btn,$text)
        {
                $txt=$_GET['findR'];
                $text=$_GET['text'];
                $cn=mysql_connect("localhost","root","");
                mysql_select_db("per_info",$cn);



                if($text==null)
                {

                $query="SELECT u.p_id 'ID', u.p_name 'NAME', u.p_add 'ADDRESS', l1.loc_name 'CITY', l2.loc_name 'STATE', u.p_gen
                        'GENDER', u.p_photo 'PIC', u.p_phone 'PH'
                        FROM p_info u, tbl_state l1, tbl_state l2
                        WHERE u.p_city = l1.loc_id
                        AND l2.loc_id = l1.loc_parent
                        AND u.p_name LIKE '".$txt."%' ORDER BY u.p_id desc LIMIT ".$btn.", 3";
                }
                else
                {

                    $query="SELECT u.p_id 'ID', u.p_name 'NAME', u.p_add 'ADDRESS', l1.loc_name 'CITY', l2.loc_name 'STATE',u.p_gen
                        'GENDER', u.p_photo 'PIC', u.p_phone 'PH'
                        FROM p_info u, tbl_state l1, tbl_state l2
                        WHERE u.p_city = l1.loc_id
                        AND l2.loc_id = l1.loc_parent
                        AND u.p_name LIKE '".$text."%' ORDER BY u.p_id desc LIMIT ".$btn.", 3";
                }
                if($rs=mysql_query($query))
                {
                    echo "<table width=\"100%\" frame=\"hsides\">
                                <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Name</font></th>
                                    <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Address</font></th>
                                    <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">City</font></th>
                                    <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">State</font></th>
                                    <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Gender</font></th>
                                    <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Photo</font></th>
                                    <th bgcolor=\"#666666\"><font color=\"#FFFFFF\">Phone No</font></th>
                                    <th bgcolor=\"#666666\"></th>
                                    <th bgcolor=\"#666666\"></th>";
                    while($row=mysql_fetch_array($rs))
                    {
                            echo "<tr>
                                        <td>".$row['NAME']."</td>
                                        <td>".$row['ADDRESS']."</td>
                                        <td>".$row['CITY']."</td>
                                        <td>".$row['STATE']."</td>
                                        <td>";if($row['GENDER']=="1")
                                                {
                                                        echo "Male";
                                                }
                                                else
                                                {
                                                        echo "Female";
                                                }
                                        echo "</td>
                                        <td>
                                            <img src=\"".$row['PIC']."\" alt=\"Pulpit rock\" width=\"50\" height=\"50\" />
                                        </td>";
                                        echo "<td>".$row['PH']."</td>
                                        <td><input type=\"button\" value=\"Edit\" onclick=\"getid(".$row['ID'].",".$btn.",'".$txt."')\"/></td>
                                        <td><input type=\"button\" value=\"Delete\" onclick=\"callDelete(".$row['ID'].",".$btn.",'".$txt."')\"/></td>
                                  </tr>";


                    }
                }
                else
                {
                    echo "error";
                }
        }
?>

我希望它会帮助你。

I hope that it will helps you

这篇关于AJAX jquery相关: - 如何调用AJAX一个AJAX加载网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:54