Я пытаюсь разработать приложение для семейного запуска, у меня есть проект Apache Cordova в Xcode с формой HTML, который должен отправить информацию о форме в скрипт, используя метод POST.
Форма работает на моем веб-сайте ( soarbay.glitch.me ), но не в симуляторе Xcode, я прикреплю код своего приложения ниже.
Спасибо за любую помощь! Лиам
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<!doctype html>
<html lang="en">
<head>
<title>SOARBAY</title>
<link rel="shortcut icon" href="waveimage.svg">
<link href="https://fonts.googleapis.com/css?family=Baloo&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Comfortaa&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/Volumes/Untitled/SoarBay/platforms/ios/www/css/mobilestyle.css" title="style">
<link rel="stylesheet" type="text/css" href="/css/style.css">
<meta name="viewport" content="width=device-width, hight=device-hight, initial-scale=1">
</head>
<body>
<!-- ORDER FORM-->
<div class="form-container">
<form name="submit-to-google-sheet">
<input name="email" type="email" placeholder="Email" required="">
<input name="firstName" type="text" placeholder="First Name">
<input name="lastName" type="text" placeholder="Last Name">
<input name="order" type="text" placeholder="Type your order here" required="">
<input name="delivery" type="text" placeholder="Delivery address (if wanted)">
<p style="font-size: 15px; color: #131F28;"><b>Please note, we only deliver in Tsawwassen. And a $3 fee will be added.</b></p>
<button type="submit">Submit</button>
</form>
<div class="loading js-loading is-hidden">
<div class="loading-spinner">
<svg><circle cx="25" cy="25" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"></circle></svg>
</div>
</div>
<p class="js-success-message is-hidden">Success!</p>
<p class="js-error-message is-hidden">Error!</p>
</div>
<script>
const scriptURL = 'https://script.google.com/macros/s/AKfycbxqSiOLVLTOyy_goyESPphj25IYVC4QTgtHZgdZU6gOUOLUFQo/exec'
const form = document.forms['submit-to-google-sheet']
const loading = document.querySelector('.js-loading')
const successMessage = document.querySelector('.js-success-message')
const errorMessage = document.querySelector('.js-error-message')
form.addEventListener('submit', e => {
e.preventDefault()
showLoadingIndicator()
fetch(scriptURL, {
method: 'POST',
body: new FormData(form)
})
.then(response => showSuccessMessage(response))
.catch(error => showErrorMessage(error))
window.alert("Your order has been recieved, we will email your recipt. Thank you!");
location.reload();
})
function showLoadingIndicator() {
form.classList.add('is-hidden')
loading.classList.remove('is-hidden')
}
function showSuccessMessage(response) {
console.log('Success!', response)
setTimeout(() => {
successMessage.classList.remove('is-hidden')
loading.classList.add('is-hidden')
}, 500)
}
function showErrorMessage(error) {
console.error('Error!', error.message)
setTimeout(() => {
errorMessage.classList.remove('is-hidden')
loading.classList.add('is-hidden')
}, 500)
}
</script>
</body>
</html>