多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
index.html: ``` <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h2>API demo</h2> <div> <div class="form-group"> <label for="pwd">短信驗證碼:</label> <input type="text" class="form-control" id="user_sms_code"> </div> <input class="submit btn btn-info" type="submit" value="Submit"> </div> </div> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script> $(".submit").click(function(){ var user_sms_code = document.getElementById('user_sms_code').value; var form = new FormData(); form.append("name", user_sms_code); // form.append("other", "other"); // postman start var settings = { "async": true, "crossDomain": true, "url": "http://localhost/python/test_2020/test3/get_data.php", "method": "POST", "headers": { "cache-control": "no-cache", "postman-token": "fa5ba7d9-b380-8d14-b26c-25e547200095" }, "processData": false, "contentType": false, "mimeType": "multipart/form-data", "data": form } $.ajax(settings).done(function (response) { console.log("Response data: "+response); console.log("JavaScript's console: "+user_sms_code); }); // postman end }); </script> </body> </html> ``` get_data.php: ``` <?php // 解决跨域问题 Allow from any origin if (isset($_SERVER['HTTP_ORIGIN'])) { // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one // you want to allow, and if so: header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Max-Age: 86400'); // cache for 1 day } // Access-Control headers are received during OPTIONS requests if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); } if (empty($_POST["name"])) { echo "Name is empty"; } else { echo $_POST['name']; echo ' | '; } exit(); ```