Jquery ajax脚本执行两次 [英] Jquery ajax script gets executed twice

查看:70
本文介绍了Jquery ajax脚本执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

' 问题:此脚本执行两次。 







  //   /< reference path =jquery-1.8.2.min.js/>  
$( document )。ready( function (){

$( #btnRegister)。click( function (){
if ($( #txtFirstname)。val()== 0 || $( #txtNickname)。val()== 0 || $( #txtGmail)。val()== 0 || $( #txtPassword)。val()== 0 || $( #txtBirth)。val()== 0 ){
alert( 数据空);
}
else {
Register();
}

});


function 注册(){

var IsMale = 1 ;
var name = $( #txtFirstname )VAL();
var nickName = $( #txtNickname )VAL();
var email = $( #txtGmail )VAL();
var 密码= $( #txtPassword )VAL();
var birthDate = $( #txtBirth )VAL();
alert(姓名);
alert(nickName);
alert(电子邮件);
alert(密码);
alert(birthDate);
alert(姓名);

$ .ajax({
type: GET
contentType: application / json; charset = utf-8

url: http:// localhost:3148 / api / values / 5

成功:功能(数据){
alert( 成功2);
alert(数据);
var obj = jQuery.parseJSON(data);
alert( ID = + obj.longPachage。 Id);
window location .href = index.html的;

},
错误: function (数据){

alert( 错误);
}
})
}

});





我尝试了什么:



i试图在没有按钮的情况下执行但仍执行两次

解决方案

document )。ready( function (){


#btnRegister)。click( function (){
if


#txtFirstname)。val()== 0 ||

I've got problem: this script gets executed twice.




/// <reference path="jquery-1.8.2.min.js" />
$(document).ready(function () {

    $("#btnRegister").click(function () {
        if ($("#txtFirstname").val() == 0 || $("#txtNickname").val() == 0 || $("#txtGmail").val() == 0 || $("#txtPassword").val() == 0 || $("#txtBirth").val() == 0) {
            alert("Data Empty");
        }
        else {
            Register();
        }

    });


    function Register() {

        var IsMale = 1;
        var name = $("#txtFirstname").val();
        var nickName = $("#txtNickname").val();
        var email = $("#txtGmail").val();
        var password = $("#txtPassword").val();
        var birthDate = $("#txtBirth").val();
        alert(name);
        alert(nickName);
        alert(email);
        alert(password);
        alert(birthDate);
        alert(name);

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
           
            url: "http://localhost:3148/api/values/5",

            success: function (data) {
                alert("Success 2");
                alert(data);
                var obj = jQuery.parseJSON(data);
                alert("ID =" + obj.longPachage.Id);
                window.location.href = "index.html";

            },
            error: function (data) {

                alert(" Error ");
            }
        })
    }

});



What I have tried:

i tried to execute without the button but still executed twice

解决方案

(document).ready(function () {


("#btnRegister").click(function () { if (


("#txtFirstname").val() == 0 ||


这篇关于Jquery ajax脚本执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆