我有一个在 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/