weixin_33686714 2015-04-30 14:35 采纳率: 0%
浏览 31

Servlet加载新页面

I have the following problem:

I have two servlets, one returns a navigation. There are categories and subcategories that the servlet gets through the DAO. I use the following script to get the servlets result on the right position:

$(document).ready(function() {                        
                $('#navigation').load('Navigation');
                $('#content').load('Content');
            });

Below my navigation div, I have a content div. As you can see, i am loading the content-servlet. In my navigation; i have the following elements:

<li><a><form action='Content' method='get'><button type='submit'>"
                                + k2.getKName() + "</button><input type='hidden' name='category' value='"+ k2.getKategorieNr() + "'/></form></a></li>

Now when I click on a subcategory, the button will call the content servlet. The problem is, that it loads a new page without the navigation. So I can only see the code that the servlet returns in a new page.

How can I get the result of the content servlet inside my previous page as it already works for my navigation servlet?

  • 写回答

1条回答 默认 最新

  • csdnceshi62 2015-04-30 15:11
    关注

    When you load your page initially, $("#navigation").load("Navigation") makes an AJAX request to your Navigation servlet and pastes the HTML response from the servlet back into an element like <div id="navigation">.

    When you click your button in the form, you are making a top-level full page request to the same servlet, and the response content will replace the whole browser window, not paste it into the page like you are getting with jQuery load.

    The easiest way to address this may be with the jQuery ajaxForm plugin: http://malsup.com/jquery/form/

    where you would do something in your ready callback like

    $(document).ready(function() {                        
                $('#navigation').load('Navigation');
                $('#content').load('Content');
                $('#formId').ajaxForm({target: '#content'});
            });
    

    Of course you need to add an ID to your form element so you can easily find it with jQuery.

    See jQuery ajax - change jQuery target value with form submit

    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了