We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Ajax Causes 302 Error on "Join My Mailing List" form

brunof9
Participant

Ajax Causes 302 Error on "Join My Mailing List" form

I am trying to create a "Join My Mailing List" form that posts to Constant Contact using an ajax call instead of a full page refresh.  When I post the llr, m, p, and ea parameters to http://visitor.r20.constantcontact.com/d.jsp I get a "302 Temporarily Moved" error.  Has anybody seen this before?  Are there any ajax example forms I can look at?  

 

Here is my form:

 

<form name="ccoptin" id="ccoptin">
        <input type="hidden" name="llr" value="<9 letter hex code>">
        <input type="hidden" name="m" value="<13 number code>">
        <input type="hidden" name="p" value="oi">
        <input name="ea" id="ea" size="20" type="text">        
        <input value="Subscribe" name="go" id="go" value="Go" type="submit" style="margin-top: 10px;">
        <div class="loading">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
        <div class="oops">Oops, an error occurred</div>        
</form>

 

Here is my Jquery code:

 

<script type="text/javascript">
$(document).ready(function() {
    
    $('#ccoptin').submit(function () {       
       
    var ea_field = $('#ea');
        if (ea_field.val()=='') {
            ea_field.css('border', '1px solid red');
            return false;
        } else {
            ea_field.css('border', 'medium none');
    }
                  
        //show the loading sign
        $('.loading').css('display', 'inline');
         
        //start the ajax
        $.ajax({
        url: "http://visitor.r20.constantcontact.com/d.jsp",
            type: "POST",
            data: $('#ccoptin').serialize(),    
            success: function (html) {       
                $('.form').fadeOut('slow');
                $('.done').fadeIn('slow');         
            },
        error: function(html) {
        $('.oops').fadeIn('slow');
        $('.loading').hide();
            }      
        });
         
        return false;
    });
});

</script>

 

 

Thanks so much!

 

 

Kev

3 REPLIES 3
DaveBerard
Moderator

The 302 you're getting is the correct response.  When the first page is hit, you will be redirected to a session based flow that is termporary.  Since it's a temporary redirect, 302 is the correct HTTP response code.  Part of the 302 response is the page to direct the browser to for the next step of the signup process.  The correct action is to follow the 302 redirect and get the next page in the flow. 

Dave Berard
Senior Product Manager, Constant Contact

So really, there is no way to do what I want to do?  A user cannot simply enter their email in a form, click submit, and be signed up with 1 click?  You must follow a multi-page process?

 

If you look at http://naughtynurisbali.com/home.html, you can see that the previous developer of this site has successfully implemented what I am trying to implement.  However, since the site is done in flash, I cannot figure out what they are sending and what they are getting back from your servers.  

 

So clearly, this can be done, but I must be missing something. 

 

Is is possible that I just ignore the 302 redirect and assume that if the server sends this, the user is successfully signed up? 

 

 

Thanks,

 

Kev

Hi Bruno,

 

What you're trying to accomplish is definitely possible, but it won't be doable through the visitor.constantcontact.com method that you were demonstrating in your previous post. That method does require a user redirection to fill out content.

 

If you were to utilize our API to make this connection, you would be able to communicate all the required info through the back end of the server and control all the redirects yourself.

Nick Galbraith
Support Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page