using jquery .ajax

Participant

using jquery .ajax

Hi I have this code below but can't get the .done to work.  Can anyone help??

 

$(document).ready(function() {
            $('#myForm').submit(function() {
                alert("the submit is working");
                var newSubscriber = JSON.stringify($('#myForm').serializeObject());
                $.ajax({

                    url: "https://api.constantcontact.com/v2/contacts?theAPIkey&theAccessToken",
                    contentType: 'application/json; charset=UTF-8',
                    type: "POST",
                    data: newSubscriber
                    
                }).done(function(){
                    alert("this worked");
                }).fail(function(){
                    alert("this didn't work");
                });
            });

        });
    </script>

1 REPLY 1
Member

Hello Robert,

 

This issue is likely the result of Cross Site Scripting(Or XSS for short) limitations present within a web browser environment. Due to these limitations, an AJAX call to pull in content from a different domain will fail. There are some methods such as CORS or JSONP that can allow for workarounds to this, but they currently are not supported by our API.

 

At this time, you would need a server-side script to POST the data, even if it simply resides on the same domain so that you can use AJAX and simply forward the request with your ser-ver side script.

 

If you do have any more questions, please let me know and I will be happy to assist you!

 

Sincerely,

Elijah G.

Tier 2 Support

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page