JQuery没有在AJAX页面上加载

时间:2015-07-21 06:18:23

标签: jquery ajax

主页index.html

    <!DOCTYPE html>
    <html>
    <head>
    <title>Insert title here</title>
    <script type="text/javascript" >
    var request;
    function sendarrr()
    {
    var v = document.getElementById('x').value;
    // var url="run.jsp?q="+String1; 


    if(window.XMLHttpRequest){  
        request=new XMLHttpRequest(); 
        }  
        else if(window.ActiveXObject){  
        request=new ActiveXObject("Microsoft.XMLHTTP");  
        }  


    try{  
        request.onreadystatechange=getInfo;  
        request.open("GET","run.jsp?q="+v,true);  
        request.send();  
        }catch(e){alert("Unable to connect to server");}  
        }  

        function getInfo(){
        if(request.readyState==4){  
        var val=request.responseText;  
        document.getElementById('dsp').innerHTML=val;  
        }  
        }  


    </script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
        alert("master");


    };
    </script>
    </head>
    <body>

    <form>
    Enter id:<input type="text" id="x"  name="tt"/>
    <input type="button" name="bt"  onclick="sendarrr()" value="click"/>
    </form>
    <span id="dsp"></span>
    </body>
    </html>
the page to be loaded in ajax  run.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import="java.sql.*" %>
    <% Class.forName("com.mysql.jdbc.Driver"); %>
</script>
    <html>
    <head>
    <title>Data</title>
    <script>
    $(document).on('click', 'a', function(event){
    alert("slave"); 
    });
</script>
    </head>
    <body>
  <% 
  String s=request.getParameter("q");  
  System.out.println("hi");
  if(s==null || s.trim().equals("")){  
  out.print("Please enter id");  
  }else{  
//  int id=Integer.parseInt(s);  
  System.out.print(s);  

        String url = "jdbc:mysql://localhost:3306/fees";
        String user = "root";
        String passswd = "password";
        System.out.println("how are you");
        Connection connection = DriverManager.getConnection(url,user,passswd);
        Statement statement = connection.createStatement();
        String sql="select * from fee1 where id=?";
        PreparedStatement ps=connection.prepareStatement(sql);  
        ps.setString(1,s); 
        ResultSet rs=ps.executeQuery();  %>
       <input type="radio" id="rd">
       <input type="text"  id="fr">
         <TABLE BORDER="1">
            <TR>
            <TH>Id</TH>
            <TH>Name</TH>
            <TH>Fee</TH>
            <TH>Course</TH>
            <TH>Occupation</TH>
            <TH>Balance</TH>
            <TH>Date</TH>
            </TR>
           <%    while(rs.next()){  { %>
           <TR>
            <TD> <%= rs.getString(5) %> </TD>
           <TD> <%= rs.getString(1) %> </TD>
           <TD> <%= rs.getString(2) %> </TD>
           <TD > <%= rs.getString(3) %> </TD>
                <TD > <%= rs.getString(4) %> </TD>
           <TD > <%= rs.getString(6) %> </TD>
           <TD> <%= rs.getString(7) %> </TD>
           </TR>
           <% } %>
        </TABLE>

       <%    } connection.close();}  %>
        </body>
        </html>

我想隐藏第二页中的广播和文本字段。当用户输入id并按下提交第二页加载ajax。在第二页我要隐藏广播和文本输入字段。 我尝试使用.on和.live进行jquery,但我无法使用它。 请帮忙.thnx

2 个答案:

答案 0 :(得分:0)

试试这个:将您的代码放在func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } 中,以确保您的DOM已准备就绪,然后在广播和文本框中调用$(document).ready(..

.hide()

编辑:当您在AJAX调用上加载页面时,隐藏单选按钮和ajax回调函数上的文本,即getInfo

$(document).ready(function(){
  $('#rd').hide();
  $('#fr').hide();
});

答案 1 :(得分:0)

在第二个jsp页面中包含jquery,添加jquery.ready函数并在其中编写代码,希望它能解决。如果从CDN加载的问题也将得到解决,您也可以尝试downloading jquery lib并加载本地系统。

相关问题