Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 621821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:55:03+00:00 2026-05-13T18:55:03+00:00

I’m working to integrate with the MailChimp API to submit a form via Ajax,

  • 0

I’m working to integrate with the MailChimp API to submit a form via Ajax, but I’m having a lot of trouble integrating the form they provide. I think this is a good opportunity for me to learn more about Ajax, but I can’t for the life of me figure out where my call is going wrong. Here’s what I have in my Ajax call:

 $('#submit-button').click(function(){
  var email = $('input#email').val();
  if(email == "you@address.com"){
   $('p#empty-error').fadeIn();

  return false;
  }

  var datastring1 = 'email=' + email;

  $.ajax({
   type: 'POST',
   url: 'mailchimp/store-address.php',
   data: datastring1,
   success: function(){
    alert('success');
   }
  });

  return false;
 });

And the PHP file to tag along:

function storeAddress(){

 // Validation
 if(!$_POST['email']){ return "No email address provided"; } 

 if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_POST['email'])) {
  return "Email address is invalid"; 
 }

 require_once('MCAPI.class.php');
 // grab an API Key from http://admin.mailchimp.com/account/api/
 $api = new MCAPI('66a7f17d87e96e439f7a2837e2963180-us1');

 // grab your List's Unique Id by going to http://admin.mailchimp.com/lists/
 // Click the "settings" link for the list - the Unique Id is at the bottom of that page. 
 $list_id = "b1ebe7c0ba";

 if($api->listSubscribe($list_id, $_POST['email'], '') === true) {
  // It worked! 
  return 'Success! Check your email to confirm sign up.';
 }else{
  // An error ocurred, return error message 
  return 'Error: ' . $api->errorMessage;
 }

}

// If being called via ajax, autorun the function
if($_POST['ajax']){ echo storeAddress(); }
?>

The script was originally written to submit via Ajax in Prototype, and I’m trying to move things over to jQuery. I’d love to know what I’m not understanding to make this happen.

More info: If it’s any help, the following call works if it’s in my HTML if I removed the javascript altogether:

<?php require_once('mailchimp/store-address.php'); if($_POST['submit']){ echo storeAddress(); } ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:55:03+00:00Added an answer on May 13, 2026 at 6:55 pm

    Ugh. When working with Ajax, do NOT attempt relative paths. That was my whole issue. Just needed to point the URL to the absolute path. Thanks for your help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.