php - jquery POST 不在 https 中返回任何结果

标签 php jquery post ssl https

我有一个在 http://mysite.com 上运行良好的 jquery 脚本

看起来像这样:

Javascript:

$('#form_changePass').live('submit', function() {
    //alert('form_changePass cliked');
    $.POST("_ajaxCall.php", $(this).serialize(),
    function(data){
        var json = eval('('+data+')');
        //alert(data);    
        if(json.message=='alert') {
            $('div.info').hide();
            $('div.alert').show().html(json.string);
        }
        if(json.message=='info') {
            $('div.alert').hide();
            $('div.info').show().html(json.string);
        }
    }
    );
    return false;
})

PHP 脚本:

if ($_POST['formType']=="form_changePass") {
.....
.......
   $arr = array( 'message' => 'info', 'string' => $INFO['updatePass']);
   echo json_encode($arr);
}

现在,当我将域移至 https 时,jquery 脚本不再起作用。我没有得到任何返回值。没有任何反应。

我还尝试在 javascript 中将 POST 更改为 getJSON,并在 php 脚本中将 $_POST 更改为 $_GET,但它仍然无法正常工作。

有什么想法吗?

最佳答案

http和https被认为是不同的域,所以是跨域问题。修复是:

header('Access-Control-Allow-Origin: https://domain.com');

将此添加到您的 php 脚本中。或者这只是在开发中,所以你不必太担心:

header('Access-Control-Allow-Origin: *');

关于php - jquery POST 不在 https 中返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10457192/

相关文章:

ajax post 在 CLASSIC asp 中获取值(value)

PHP pg_connect 连接字符串

php - 无法重新声明的解决方法?

php - MySQL插入缩放问题

html - 获取 url 时如何强制 Web 浏览器使用 POST?

php - 为什么jquery ajax发送多次?

php - Doctrine2 一对多/多对一关系

jquery - 如何在没有滚动条的情况下向下和向上滚动?

javascript - 如何计算数字和逗号中有空格的表中的值

javascript - 从除 1 以外的所有元素中删除类