从url变量填充电子邮件字段

时间:2016-01-22 16:01:44

标签: javascript jquery

我尝试从网址变量Ex:https://my.site.org/site/SignupPage.html?email=jsavage980%40gmail.com填充表单上的电子邮件字段,但它大部分都有效,除非它没有从电子邮件地址中提取“@”。这是我的代码:

Feb 14, 2016 1:05:00 PM org.apache.catalina.startup.HostConfig undeploy
INFO: Undeploying context [/home]
Feb 14, 2016 1:05:03 PM org.apache.catalina.loader.WebappClassLoader modified
SEVERE:     Resource '/WEB-INF/lib/args4j-2.0.26.jar' is missing
Feb 14, 2016 1:05:03 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [] has started
Feb 14, 2016 1:05:03 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.
Feb 14, 2016 1:05:03 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [] appears to have started a thread named [New I/O  worker #1] but has failed to stop it. This is very likely to create a memory leak.
Feb 14, 2016 1:05:03 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [com.ning.http.client.providers.netty.NettyAsyncHttpProvider.ThreadLocalBoolean] (value [com.ning.http.client.providers.netty.NettyAsyncHttpProvider$ThreadLocalBoolean@288f896e]) and a value of type [java.lang.Boolean] (value [false]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Feb 14, 2016 1:05:03 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [org.jboss.netty.util.CharsetUtil$1] (value [org.jboss.netty.util.CharsetUtil$1@6e49414c]) and a value of type [java.util.IdentityHashMap] (value [{US-ASCII=sun.nio.cs.US_ASCII$Encoder@6e14afdd}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Feb 14, 2016 1:05:03 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [] created a ThreadLocal with key of type [com.ning.http.client.providers.netty.NettyAsyncHttpProvider.ThreadLocalBoolean] (value [com.ning.http.client.providers.netty.NettyAsyncHttpProvider$ThreadLocalBoolean@288f896e]) and a value of type [java.lang.Boolean] (value [true]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Feb 14, 2016 1:05:03 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /var/lib/tomcat7/webapps/home does not exist or is not a readable directory
    at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:136)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:5089)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5269)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3988)
    at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:425)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
    at java.lang.Thread.run(Thread.java:745)

Feb 14, 2016 1:05:03 PM org.apache.catalina.core.StandardContext reload
SEVERE: Exception starting Context with name []
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3988)
    at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:425)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1345)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Error in resourceStart()
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5270)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 8 more

Feb 14, 2016 1:05:03 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [] is completed
Feb 14, 2016 1:06:20 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/home.war

2 个答案:

答案 0 :(得分:1)

首先,您必须正确解码您的网址:

var url = decodeURIComponent(this.location);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent



document.getElementById('output').textContent = decodeURIComponent(document.getElementById('input').textContent);

<div id="input">https://my.site.org/site/SignupPage.html?email=jsavage980%40gmail.com</div>
<div id="output"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我正在使用这个小的jQuery插件来读取和解码查询参数:

/*
 * jQuery plugin to get parse the URI query parameters.
 * E.g. ?a=123&b=567 -> get parameters with $.uriQuery["a"] and $.uriQuery["b"]
 */
(function($)
{
    $.uriQuery = (function()
    {
        var a = window.location.search.substr(1).split('&');
        var b = {};
        if (a!="")
        {
            for (var i=0; i<a.length; ++i)
            {
                var p = a[i].split('=');
                if (p.length!=2)
                    continue;
                b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
            }
        }
        var i = window.location.hash.indexOf('?');
        if (i>=0)
        {
            a = window.location.hash.substr(i + 1).split('&');
            if (a!="")
            {
                for (var i=0; i<a.length; ++i)
                {
                    var p = a[i].split('=');
                    if (p.length!=2)
                        continue;
                    b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
                }
            }
        }
        return b;
    })()
})(jQuery);

var i = window.location.hash.indexOf('?');开始的部分不是必需的,我需要这个从angularjs程序中的URI获取查询参数(angularjs路由器将#/...添加到URI)。