发送ajax订阅与json的电话

时间:2015-08-12 08:02:46

标签: ajax

我正在尝试让用户使用sendy订阅表单(通过ajax)在网站上订阅。

问题是它没有显示错误,console.log卡住了“登录...”。

jQuery( document ).ready(function() {

    jQuery("#emailListSignupForm").submit(function(e) {

        console.log('submitting');
        e.preventDefault();

        var thisis = jQuery( this );

        thisis.find('input').attr("disabled", "disabled");

        jQuery("#status").text("Signing You in...");


        var testList = "ID GOES HERE";
        var name = thisis.find('input[name="name"]').val();
        var email = thisis.find('input[name="email"]').val();
        var sendyUrl = "http://PATH GOES HERE/subscribe";
        var dataObject = {name: name,email: email,list: testList};


        window.message = function(text, color) {
            jQuery("#status").css("color", color).text(text);
        }

        jQuery("#status").text("Sending details....");


        jQuery.ajax({

            url: sendyUrl,
            type: 'POST',
            dataType: "jsonp",
            data: dataObject,
            success: function( response ) { 
            console.log( response );                
                if ( response ) {
                    thisis.find('input').removeAttr("disabled");
                    if (response == "Some fields are missing.") {
                      jQuery("#status").text("Please fill in your name and email.");
                    } else if (response == "Invalid email address.") {
                      jQuery("#status").text("Uhoh - that doesn't look like an email address. Could you please enter your email again?"); 
                    } else if (response == "Invalid list ID.") {
                        jQuery("#status").text("Oops - something went wrong (I tried to sign you up for an email list that doesn't exist). To get added, send me an email at christian@gen.co instead!"); 
                    } else if (response == "Already subscribed.") {
                        jQuery("#status").text("You're already subscribed!"); 
                    } else {
                      jQuery("#status").text("You're subscribed!");
                      jQuery("#status").css("color", "green");
                      thisis.find('input, button').hide();
                    }
                  } else {
                    alert("Sorry, unable to subscribe. Please try again later!");
                    jQuery("#status").text("Oops - something went wrong (my email list server just had an error). To get added, send me an email at christian@gen.co instead!");
                  }
            }

        });

    });


});

0 个答案:

没有答案