我有一些jQuery正在进行ajax调用。该脚本仅在Win 8.1上的IE和Chrome中出现问题,但是,我更改了一些内容(包括省略了可能导致问题的关闭php标记),现在IE正常工作,并且我在Chrome上的Win 8.1上运行,但是客户仍在报告问题。
任何人都可以看到我的脚本出现问题会导致Chrome上的Win 8.1失败吗? (顺便说一句,Safari和Opera可能没有经过客户测试,因此可能也没有对它们进行测试)。
我已经在SO和其他问题/答案网站以及许多不同的相关论坛上阅读了几个小时和几个小时。我已经尝试了许多不同的建议而没有运气。
显然,人们首先想到的是跨域问题,该网站托管在“附加”域上,但我在相同的URL上调用脚本。我应该使用主域名来调用它吗? (我现在无法弄清楚主域名是什么,请看这个问题:Find original main domain name based on add-on domain name)
客户端正在从ajax错误块中收到警报:
readystate = 0
status = 0
responseText = ''
statusText = 'error'
非常感谢任何帮助,我已经坚持了好几个星期了。
这是我的jQuery:
$('#bkdl-submit').on('click', function(e) {
e.preventDefault();
var tempvar = $('#bkdl-email').val();
if (IsEmail(tempvar)) {
$('#loading-image').show();
$('#bkdl-submit').hide();
$.ajax({
url: "http://addondomain.com/wp-content/themes/html/bkdl-ajax.php?nocache="+Date.now(),
method: "POST",
data: {
email: tempvar
},
success: function (data) {
$("#bkdl-email").css('background-color', '#f00');
$("#bkdl-email").val('');
$("#hidlink").attr('href', data);
$("#hidlink").text('Click to Download');
$("#hidlink").show();
$("#bkdl-submit").hide();
},
complete: function () {
$('#loading-image').hide();
},
error: function (xhr, strError, strHttpStatus) {
alert(JSON.stringify(xhr, null, 2));
alert(strHttpStatus);
}
});
} else {
alert('Invalid Email');
}
return false;
});
AJAX PHP脚本,如果有帮助......
<?php
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
if(!IS_AJAX) {die('Restricted access1');}
$pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST'));
if($pos===false) { die('Restricted access'); }
require_once 'Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
define("APIKEY", "xxxxxxxxxxxxxxxxxxxxxxxxxx");
define("ACCESS_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$cc = new ConstantContact(APIKEY);
// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
$email = strip_tags(htmlentities(trim($_POST['email'])));
$action = "Getting Contact By Email Address";
try {
// check to see if a contact with the email addess already exists in the account
$response = $cc->getContactByEmail(ACCESS_TOKEN, $email);
// create a new contact if one does not exist
if (empty($response->results)) {
$action = "Creating Contact";
$contact = new Contact();
$contact->addEmail($_POST['email']);
$contact->addList('xxxxxxxxxxxxx');
$contact->first_name = '';
$contact->last_name = '';
$returnContact = $cc->addContact(ACCESS_TOKEN, $contact);
// update the existing contact if address already existed
} else {
$action = "Updating Contact";
$contact = $response->results[0];
$contact->addList('xxxxxxxxxxxx');
$contact->first_name = '';
$contact->last_name = '';
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);
}
echo 'http://addondomain.com/wp-content/themes/html/giveaway.pdf';
// catch any exceptions thrown and email to dev
} catch (CtctException $ex) {
$errorvar = print_r($ex->getErrors(), true);
mail('deverrors@gmail.com', 'test', $errorvar);
die();
}
} else {
echo 'Invalid Email'; exit;
}
exit;