te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>java - How do I inject another JSP page into a <div> when clicking a link? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How do I inject another JSP page into a <div> when clicking a link? - Stack Overflow

programmeradmin4浏览0评论

I have two different divisions in a JSP page. One contains a menu of links, when clicked the div2 (id-content) loads different pages accordingly. I am doing something like -

<div id="menu">
<ul class="navbar">
  <li><a name="login" href="Login.jsp" onclick="changeContent()">Login</a>
   </li></div>

and in the script I have something as -

<script language="JavaScript">
function changeContent() {
    document.getElementById('content').load('Login.jsp');
}
</script>

I also tried -

document.getElementById('content').innerHTML=
"<jsp:include page="Login.jsp">"; 

None of the ways worked. Please suggest how should I

I have two different divisions in a JSP page. One contains a menu of links, when clicked the div2 (id-content) loads different pages accordingly. I am doing something like -

<div id="menu">
<ul class="navbar">
  <li><a name="login" href="Login.jsp" onclick="changeContent()">Login</a>
   </li></div>

and in the script I have something as -

<script language="JavaScript">
function changeContent() {
    document.getElementById('content').load('Login.jsp');
}
</script>

I also tried -

document.getElementById('content').innerHTML=
"<jsp:include page="Login.jsp">"; 

None of the ways worked. Please suggest how should I

Share Improve this question edited Sep 9, 2012 at 0:25 Nihal Sharma asked Sep 9, 2012 at 0:20 Nihal SharmaNihal Sharma 2,43712 gold badges44 silver badges57 bronze badges 1
  • 3 document.getElementById('content').load() will not do anything. If you're trying to load the content asynchronously, you need to use AJAX methods (or jQuery or some other specialty library/framework with shortcut methods). The last "method" probably doesn't work because it contains double quoted attributes, is not being parsed server-side, or whatnot. That could work, but probably not the way you've shown (for instance, put the login markup in the body and then show it on click). – Jared Farrish Commented Sep 9, 2012 at 0:57
Add a ment  | 

4 Answers 4

Reset to default 4

Try jquery..

function changeContent() {
    $('#content').load('Login.jsp');
}

The solution is to use Ajax, which will asynchronously retrieve your page content that can be pasted in with the innerHTML method. See my answer to a similar question of how an Ajax call works and some introductory links.

As to why your examples in your answer don't work, in the first case there is no load() method on an Element object (unless you've defined one yourself and not shown it). In the second example, as one of the question ments says, there is probably something causing a syntax error in the javascript.

As an FYI, when there is a syntax error in some javascript in a web page, the current expression being parsed and the rest of the <script></script> block will be ignored. Since this is inside a function declaration, that function will never get defined. For instance, an embedded quote in the included page will end the string for the innerHTML assignment. Then the javascript parser will try to parse the remainder of the HTML causing a syntax error as the HTML will not be valid javascript.

We use jquery. Add a click event handler to the anchor elements. In the click handler call $('#content').load(your_url);. You might want to use the load(url, function() { ...}) version. More info here http://api.jquery./load/

Your initial page es down from the server. It's displayed by the browser. When you click on a link (or a button) in the browser, you want to fill the second div with new HTML. This is is a perfect job for an AJAX request. What the AJAX object in the browser does, is to send a POST (or whatever) string to the server. And then the Ajax object receives the HTML response back from the server. And then you can display that response data which the AJAX object contains, anywhere you want.

发布评论

评论列表(0)

  1. 暂无评论