问题描述
我在safari 9上的js有问题,我的代码:
const subscribeForm = document.querySelector('#subscribeForm');
subscribeForm.addEventListener('submit', function (e) {
e.preventDefault();
fetch(this.action + '?action=subscribe&email=' + this[0].value + '&site=' +<? print $this->id_site ?>)
.then((r) => {
return r.json();
})
.then((r) => {
this.insertAdjacentHTML('afterend', `<p>${r.response}</p>`)
});
});
错误语法错误:意外令牌'>'
请给我一些想法,在其他浏览器上都很好。
1楼
看一下 Safari 9不支持箭头功能,而是使用function() {
代替。
与和相同的也已在Safari 10中添加,对于fetch,您可以像一样使用 。
因此,您的代码应如下所示:
<script src="https://unpkg.com/unfetch/polyfill"></script>
<script>
var subscribeForm = document.querySelector('#subscribeForm');
subscribeForm.addEventListener('submit', function (e) {
e.preventDefault();
fetch(this.action + '?action=subscribe&email=' + this[0].value + '&site=' +<? print $this->id_site ?>)
.then(function(r) {
return r.json();
})
.then(function(r) {
this.insertAdjacentHTML('afterend', '<p>' + r.response + '</p>');
});
});
</script>
您还需要使用Safari 10中添加的进行操作,您可以尝试 。