Javascript 异步请求失败,而同步请求通过并按预期工作

Javascript 异步请求失败,而同步请求通过并按预期工作,javascript,php,jquery,asynchronous,cross-domain,Javascript,Php,Jquery,Asynchronous,Cross Domain,我已经调整这个脚本一段时间了,正如我在问题中提到的,我的代码在非异步模式下工作得很好,而当我更改async:true时,代码就失败了 这是我的密码 $.ajax({ type : "POST", url : "http://someotherserver.com/sendmail.php", data: { resp: data }, async: fa

我已经调整这个脚本一段时间了,正如我在问题中提到的,我的代码在非异步模式下工作得很好,而当我更改
async:true
时,代码就失败了

这是我的密码

       $.ajax({
                type : "POST",
                url  : "http://someotherserver.com/sendmail.php",
                data: { resp: data },
                async: false
                })

                    .done(function( msg )
                     {
                        alert(msg); // Works when async:false              
                     })                         

                     .fail(function(jqXHR, textStatus)
                     {
                       if(textStatus == 'timeout')
                       {     
                        alert('Failed from timeout');
                       }
                     });
sendmail.php
中没有什么内容,它位于我朋友的服务器上,启用了
CORS

sendmail.php

<?php
file_put_contents('request.txt',json_encode($_REQUEST));
echo "filecreated";

如果发出CORS请求,则必须添加
Origin
HTTP头,但它确实在同步模式下工作。CORS是在PHP文件所在的另一台服务器上启用的。这可能受服务器细节的影响。但是,正常请求应该包含
来源:
标题。否则它就不是CORS请求了。@hindmost,谢谢,但这个答案说这与JS代码无关@Catherinetler在同步模式下工作仍然很奇怪。知道为什么吗?