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 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线