dongshi7350 2013-06-17 15:57
浏览 54

MailChimp无法使用AJAX - PHP脚本破解

I am attempting to construct an ajax form that integrates with the mailchimp API via a PHP script. I am passing variables successfully from AJAX using the form below:

      <div id="mailchimp_form">
        <p>Enter your email address below to get first dibs!</p>
        <form>
         <input type="email" value="" name="EMAIL" placeholder="Enter your email address to get first dibs...">
         <button class="btn">Submit</button>
        </form>
      </div>
    </div>
  </div>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

  $("#mailchimp_form .btn").click(function (){

    dataString = $("#mailchimp_form form").serialize();

    $.ajax({  
      type: "POST",  
      url: "includes/subscribe.php",  
      data: dataString,  
      success: function(returnval) {  
       alert(returnval);
      }  
    });  

  });

}); 
</script>

I know this because when I echo $_POST["EMAIL"] I get a response. When I pass the variable to the API call that is when I have a problem. The entire script just dies, no errors from the API, no errors from php, absolutely nothing, I know it dies because nothing echoes after the api call. What's ever stranger is when I run the API call with $my_email = "test@testemail.com" and run the PHP script by itself, everything works fine. All other API calls also work fine with ajax, listSubscribe is the only one I have any issues with. IF I type in an non-email into the email field the listSUbscribe api function reports it as an error (validation on the API's part is clearly working as well), but if i do type an email, absolutely nothing happens. No users are added to the list and nothing is in my inbox, spam or trash folders.

Can anyone give me even a slight clue as to what the issue could be, im completely lost on this one. The PHP code is beow:

function test($apikey,$listId) {
$api = new MCAPI($apikey);
$my_email = $_POST["EMAIL"];
$merge_vars = array("FNAME"=>'Sichard', "LNAME"=>'Wright');
$api->listSubscribe( $listId, $my_email, $merge_vars );

echo $my_email;
echo $api->errorCode;
}

test($apikey,$listId);

My includes:

require_once 'MCAPI.class.php'; require_once 'config.inc.php'; //contains apikey

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退
    • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
    • ¥50 invest生境质量模块
    • ¥15 nhanes加权logistic回归,svyglm函数