私は単純なサインアップメーリングリストのフォームを持っています。ユーザーの電子メールアドレスをstore-address.phpファイルに送信します。 jQueryのajaxオブジェクトを使用してPHPファイルにリクエストを送信し、応答を受け取ります。PHPファイルが正しく設定されていてもAjaxレスポンスはありません
問題は、私は、PHPファイルからの応答を取得していないです。リクエストでキャッシュをfalseに設定しようとしました。
http://www.fifthtribe.com/inc/store-address.php?ajax=true&cache=false&email=test4%40gmail.com
私はそれが動作してくれREPONSEを与えるそのようにそれを行う:私もそうのようなURLを介して情報を送信しようとしました。しかし、私がAJAXを通してそれをするとき、それは私に応答を与えません。これはFirebugのである:
そしてここでは、私のコードからの抜粋です:
HTML:
<div id="mlist">
<form id="mlist_form" method="POST" action="">
<input type="text" id="email" name="email" placeholder="Email" />
<input type="submit" id="submit_btn" value="Join" />
</form>
<div id="response"></div>
</div>
はJQuery:
/* Add to mailing list */
$("#mlist_form").submit(function(e){
//$('#response').append('<div id="thanks-mce"><div id="mce-arrow"></div>Thanks for signing up!</div>');
var email = escape($('#email').val());
e.preventDefault();
data = {
"ajax" : "true",
"email" : email,
"cache" : "false"
}
$.ajax({
type: "POST",
url: 'inc/store-address.php',
data: data,
success: function(msg){
// successfully signed up
$('#response').html(msg);
$('#email').val('');
},
error: function(err){
// error while signing up
$('#response').html('Error: Is your email correct?');
}
});
return false;
});
PHP: 関数storeAddress(){
// Validation
if(!$_GET['email']){ return "No email address provided"; }
if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_GET['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('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-us4');
// 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 = "xxxxxxxx";
if($api->listSubscribe($list_id, $_GET['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($_GET['ajax']){ echo storeAddress(); }
?>
は 'ますprint_r($ _ REQUEST)してみてください;'とあなたのデータは –