I need send mysql data from one server to select box in other server:
When i tried send it on one server it works. But when i go across the domain, there is any problem.
<p id="demo"></p>
<script>
const dbParam = JSON.stringify({"limit":1000});
const xmlhttp = new XMLHttpRequest();
xmlhttp.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
xmlhttp.open("GET", "http://xxx.cz/json_materials.php?x=" + dbParam);
xmlhttp.send();
</script>
</body>
</html>
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$obj = json_decode($_GET["x"], false);
define('HOST', '');
define('DB', '');
define('LOGIN', '');
define('PASSWD', '');
$conn = new mysqli(HOST, LOGIN, PASSWD, DB);
$stmt = $conn->prepare("SELECT p_name FROM products LIMIT ?");
$stmt->bind_param("s", $obj->limit);
$stmt->execute();
$result = $stmt->get_result();
$outp = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode($outp);
New contributor
Petr Voráč is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.