doujianmin6527 2014-12-20 03:05
浏览 39
已采纳

为什么我的简报形式无法在Amazon CloudFront上运行?

I am using HTML and using amazon EC2 (Linux free tier). I would like to use CloudFront, but my newsletter won't work. I am not an AWS expert, and I don't have a clue as to why it won't work on CloudFront.

My newsletter form looks like this:

 <form id="subscribe" class="form" action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
        <div class="form-group form-inline">
          <input size="15" type="text" class="form-control required" id="NewsletterName" name="NewsletterName" placeholder="Your name" /> 
          <input size="25" type="email" class="form-control required" id="NewsletterEmail" name="NewsletterEmail" placeholder="your@email.com" /> 
          <input type="submit" class="btn btn-default" value="SUBSCRIBE" />
          <span id="response">
            <? require_once('assets/mailchimp/inc/store-address.php'); if($_GET['submit']){ echo storeAddress(); } ?>
          </span>
        </div>
      </form>

and my js file looks like this:

jQuery(document).ready(function() {
jQuery('#subscribe').submit(function() {
    // update user interface
    jQuery('#response').html('<span class="notice_message">Adding email address...</span>');


    var name = jQuery('#NewsletterName').val().split(' ');

    var fname = name[0];
    var lname = name[1];

    if ( fname == '' ) { fname=""; }
    if ( lname == '' || lname === undefined) { lname=""; }
    // Prepare query string and send AJAX request
    jQuery.ajax({
        url: 'assets/mailchimp/inc/store-address.php',
        data: 'ajax=true&email=' + escape(jQuery('#NewsletterEmail').val()),
        success: function(msg) {

            if (msg.indexOf("Success") !=-1) {
                jQuery('#response').html('<span class="success_message">Success! You are now 
subscribed to our newsletter!</span>');
            } else {
                jQuery('#response').html('<span class="error_message">' + msg + '</span>');
            }
        }
    });

    return false;
});
});

and my php file looks like this:

<?php

function storeAddress(){

require_once('MCAPI.class.php');  // same directory as store-address.php

// grab an API Key from http://admin.mailchimp.com/account/api/
$api = new MCAPI('mymailchimpapi');

$merge_vars = Array( 
    'EMAIL' => $_GET['email'],
    'FNAME' => $_GET['fname'], 
    'LNAME' => $_GET['lname']
);

// 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 = "myuniqueid";

if($api->listSubscribe($list_id, $_GET['email'], $merge_vars , $_GET['emailtype']) === true) {
    // It worked!   
    return 'Success!&nbsp; Check your inbox or spam folder for a message containing a 
confirmation link.';
}else{
    // An error ocurred, return error message   
    return '<b>Error:</b>&nbsp; ' . $api->errorMessage;
}

}

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

The form works when I access it without using CloudFront, but I am worried of the server bandwidth that's why I want to use CloudFront. What happens is that when you click the submit button, the "adding email address" message will just appear for 1 second, and the email address entered is ignored.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用