我有一个$.ajax
,它在php中运行文件并传递一个变量(电子邮件andress)。该文件运行得很好,但xhr.status
是0
。
这是代码:
$.ajax({
type: 'POST',
url: 'file.php',
data: { email: destinatario },
complete: function(xhr,status){
$('#momentaneo, #force').remove();
alert(xhr.status);
if(xhr.status === 200){
alert('ok');
}
else{
alert('no');
}
}
});
这个file.php
,独立于xhr.status
,运行良好,它为我的时事通讯添加了一个用户。所以我不认为这个文件有问题。。它有"0755"权限文件,如果我用浏览器运行file.php
的url,就没有问题。
问题是xhr.status
就是0
,我不明白为什么。。。我读到这可能是"跨站点脚本",但我不知道在我的情况下是否可行。我还尝试更改div
中的标签form
,但没有更改。
我还添加了file.php
:
<?php
include('wrapper.php');
$apikey = "76a21109637d7391d1e68e9680e6";
voxmail_init($apikey);
voxmail_user_subscribe(array('mail' => $_POST['email'],'privacy' => 1),$_SERVER['REMOTE_ADDR']);
$header = "Content-type: text/html";
header($header);
print('<b>ok</b>');
?>
voxmail是新闻通讯服务的API(我敢肯定101%的API没有问题)
我希望你能帮助我,非常感谢并为我的英语
我认为问题在于,当status
作为完整回调中的第二个参数传递给您时,您正在检查xhr.status
。试试这个:
$.ajax({
type: 'POST',
url: 'file.php',
data: { email: destinatario }
}).always(function(){
$('#momentaneo, #force').remove();
}).then(function(){
console.log.apply(console, arguments);
alert('ok');
}, function(){
console.warn.apply(console, arguments);
alert('no');
});
控制台语句仅用于调试目的,可以删除。