weixin_33728268 2013-08-28 07:11 采纳率: 0%
浏览 10

.jsp页面中的ajax,jquery

I m new to jquery nd ajax kindly help me in this code as dis code is not working it is showing complete html code instead of text(hiiiii) A.html

<html>
<head>

<title>Insert title here</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#btn").click(function(){
    $.post("hello.jsp",function(data,status){
      $("#mydiv").text(data);
    });
  });
});
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" id="btn">Request data</button>
<div id="mydiv"></div>
</body>
</html> 

hello.jsp

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
   <%
    int i=0;
    int j=++i;
    out.println(" hiiiiii" +(j));
    %>
    </body>
    </html>

output ajax a button jsp page's code

  • 写回答

2条回答 默认 最新

  • weixin_33690367 2013-08-28 07:13
    关注

    just change this

     $("#mydiv").text(data);
    

    to

     $("#mydiv").html(data);
    

    and also check this What is the difference between jQuery: text() and html() ?

    评论

报告相同问题?