-2

I recently tried to use AJAX in a PHP form, but it doesn't work. I don't understand why.

This is mi code:

<!DOCTYPE html>
<html lang="es">
<head>
 <title></title>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
$(document).ready(function(){
 $("#btn-enviar").click(function(){
  var url = "http://www.interplazaindependencia.com/dame-datos.php";
  $.ajax({
   type: "POST",
   url: url,
   data: $("#formulario").serialize(),
   success: function(data){
    $("#resultado").html(data);
   }
  });
  return false;
 });
});
</script>
</head>

<body>
<form method="post" id="formulario">
 Introduce un nombre: <input type="text" name="nombre">
 <input type="button" id="btn-enviar" value="enviar">
 <div id="resultado"></div>
</form>
</body>
</html>

Can someone help me? Please, I have tried for hours and I can't solve it.

1 Answers1

0

When your code is run, this error is returned in the Chrome Developer Console:

XMLHttpRequest cannot load http://www.interplazaindependencia.com/dame-datos.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

You can find more information about this error on this topic.

Community
  • 1
  • 1
BryanLavinParmenter
  • 416
  • 1
  • 8
  • 20