跨域AJAX POST脚本可以工作,但成功时没有回调

时间:2014-06-02 12:43:09

标签: php jquery ajax cors jquery-forms-plugin

在http网站上,我有一个表单,其中提交指向其他域:

<form enctype="multipart/form-data" action="https://(...)/script.php" method="post"> (...)

为了启用跨域AJAX,我已添加到script.php:

<?php header('Access-Control-Allow-Origin: *'); ?>

现在可以访问脚本,但我想它不会给服务器回复,因为成功的回调方法:

$("form").ajaxSubmit({
                    target:        '.afterSend',
                    beforeSubmit:  showRequest,
                    success:       showResponse

                });

function showResponse(responseText, statusText, xhr, $form)  { 

    $(".afterSend").removeClass("preloader");               
    $(".afterSend").empty().append(responseText);

} 
尽管成功进行了AJAX调用,

永远不会激活: enter image description here

当两个文件都位于同一个域时,它才有效。

编辑:
当我添加选项complete: showResponse时,没有responseText
当我添加error: showResponse时,我收到警告:

  

警告:无法修改标头信息 - 已发送的标头   (......)第14行

responseText显示。

因此,由于这个警告,jQuery认为呼叫是不成功的。

0 个答案:

没有答案