In the front-end, to solve the cross-domain time always seem so disgusting, what Jsonp Ah, Ajax ah, cors ah what, always feel is in the loopholes in the cross-domain, in fact, in PHP file only need to add a piece of code can cross the domain, the front-end you how to write or how to write, Post,get casually use:
Header ("access-control-allow-origin:*");
Header ("access-control-allow-origin:*"); Add this sentence to achieve the front-end cross-domain function GetKey ($key, $default = "") { return trim (Isset ($_request[$key])? $_request[$key]:$ default);} $id = GetKey ("id"), $conn = Mysqli_connect ("localhost", "root", "" "," test ") or Die (" Connection Failed "), $conn->query (" Set names UTF8 $sql = "SELECT * from Data where". $id. ' is not null '; $result = $conn->query ($sql); $arr = [];while ($row = $result FETCH_ASSOC ()) { Array_push ($arr, Json_encode ($row));} $json = Json_encode ($arr); JSON data Print_r ($json);
PHP Background code solves cross-domain issues