提交javascript和表单

时间:2014-04-14 10:03:14

标签: javascript html

提交无效的问题 当我点击提交时,它会继续操作而不是提交

<form action="http://www.client.ad-saver.com/Registration/SimpleRegister?      email=yusuyaauu@gmail.com" onsubmit="return myFuncmyFunc();"  method="POST">
           <input class="email" type='text' name='email' placeholder='E-mail' value=""/>
           <input class="submit" id="sub" type="submit" value='Регистрация' name='reg'/>
  </form>

这是我的js:

function myFuncmyFunc () {
    var crossdomainrequest = {
        callbackCounter: 0,
        fetch: function (url, callback) {
            var fn = 'JSONPCallback';
            window[fn] = this.evalJSONP(callback);
            url = url.replace('=JSONPCallback', '=' + fn);
            var scriptTag = document.createElement('SCRIPT');
            scriptTag.src = url;
            document.getElementsByTagName('HEAD')[0].appendChild(scriptTag);
        },
        evalJSONP: function (callback) {
            return function (data) {
                var validJSON = false;
                if (typeof data == "string") {
                    try {
                        validJSON = JSON.parse(data);
                    } catch (e) {
                    }
                } else {
                    validJSON = JSON.parse(JSON.stringify(data));
                }
                if (validJSON) {
                    callback(validJSON);
                } else {
                    throw ("JSONP call returned invalid or empty JSON");
                }
            }
        }
    }

crossdomainrequest.fetch("http://www.client.ad-saver.com/Registration/EmailValidation?email=wdlebedcom",  function (data) {
        alert(data.message);        
    });
}

我需要提醒,然后在提交后获取行动和行动地点

2 个答案:

答案 0 :(得分:1)

myFuncmyFunc()应该返回false以防止将表单提交给服务器

答案 1 :(得分:1)

做一件事。

<form>
       <input class="email" type='text' name='email' placeholder='E-mail' value=""/>
       <input class="submit" id="sub" type="button" value='Регистрация' name='reg' onClick="return myFuncmyFunc();"/>
</form>

myFuncmyFunc()中编写所有操作和方法。