【发布时间】:2019-12-05 19:06:01
【问题描述】:
我无法向 php 发送信息,它被阻止了。
跨源请求仅支持以下协议方案:http、data、chrome、chrome-extension、https。
我使用了不同的,只有三分之一的 pc 使代码工作。
$(document).on('ready', function() {
$('#loginAjax').click(function() {
$.ajax({
type: 'POST',
url: 'prueba.php',
dataType: 'json',
data: { myusuario: "hola" },
success: function(response) {
$('#result').html(response);
},
error: function() {
$("#result").html("no vas a aprobar");}
});
});
$('#redRegistrar').click(function() {
location.href = 'registro.html';
});
});
<?php
header("Access-Control-Allow-Origin: *");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$recibido = $_POST['myusuario'];
echo json_encode( $recibido );
}
?>
我希望它会说hola。
【问题讨论】:
-
file:///C:/xampp/htdocs/app_bloqui/prueba.php' from origin 'null' 已被 CORS 策略阻止:跨源请求仅支持协议方案:http,数据,铬,铬扩展,https。
-
我为你修正了代码格式。