weixin_33713350 2016-04-29 11:09 采纳率: 0%
浏览 19

AJAX隐藏调用jsp页面

i have my index.jsp :

<%@ page pageEncoding="UTF-8"%>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>Hello</title>
    </head>
    <body>
       Hello !
       <input type="hidden" name="ip" value="" id="ip">
    <script>

        var ip = document.getElementById("ip");
        ip.value = userip;

    </script>
    </body>
</html>

I have another view.jsp which one take an argument like that :

http://localhost:8200/view/view.jsp?ip=IP_VALUE

Then when i open this link and replace IP_VALUE by anything, this value is automatically added to my database.

But now i'm trying to call hiddenly this jsp page, i mean i want that when the user open my page, my javascript variable "ip" is past to my view.jsp like :

http://localhost:8200/view/view.jsp?ip= "ip"

But i want that the user don't see that, so i don't want any redirection or form, just an AJAX hidden call of my jsp.

view.jsp is on the same folder than my index.jsp

How can i do that hiddenly ?

  • 写回答

1条回答 默认 最新

  • weixin_33719619 2016-04-29 11:24
    关注

    Try this:

    <%@ page pageEncoding="UTF-8"%>
    <html>
        <head>
            <meta charset="UTF-8"/>
            <title>Hello</title>
        </head>
        <body>
           Hello !
           <input type="hidden" name="ip" value="" id="ip">
        <script>
    
            var ip = document.getElementById("ip");
            ip.value = userip;
    
            var xmlhttp =  new XMLHttpRequest();
    
            xmlhttp.open('GET', 'view.jsp?ip' + userip, true);
    
            xmlhttp.onreadystatechange = function() {
    
                if (xmlhttp.readyState == 4) {
    
                    if(xmlhttp.status == 200) {
    
                        //alert(xmlhttp.responseText);
                    }
                }
            };
            xmlhttp.send(null);
    
        </script>
        </body>
    </html>
    

    You can send any value to any page by XMLHttpRequest object.

    评论

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败