Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在调用URL时对JavaScript代码感到困惑,不确定是否需要Ajax调用_Javascript_Html_Ajax - Fatal编程技术网

在调用URL时对JavaScript代码感到困惑,不确定是否需要Ajax调用

在调用URL时对JavaScript代码感到困惑,不确定是否需要Ajax调用,javascript,html,ajax,Javascript,Html,Ajax,我有一个.html文件 在该文件中,有如下链接: <a href="https://www.someOtherWebsite.com/" onclick="clicked('https://www.MyWebsite.com/send_emai.php?subject=hello&body=test')">Some text</a> 不需要这个函数返回。我还需要Ajax吗?这段代码是正确的还是缺少一些语法?我上次使用JavaScript和Axax是在10年前,所

我有一个.html文件

在该文件中,有如下链接:

<a href="https://www.someOtherWebsite.com/" onclick="clicked('https://www.MyWebsite.com/send_emai.php?subject=hello&body=test')">Some text</a>
不需要这个函数返回。我还需要Ajax吗?这段代码是正确的还是缺少一些语法?我上次使用JavaScript和Axax是在10年前,所以这有点困难:)


谢谢

如果您先点击发送电子邮件的url,然后导航离开,会怎么样

我不知道fetch是如何工作的,但您可以尝试以下方法:

<a href="https://www.someOtherWebsite.com/" onclick="clicked('https://www.MyWebsite.com/send_emai.php?subject=hello&body=test')">Some text</a>
一些文本
已单击函数(url){
//你的服务器呼叫
取('https://www.MyWebsite.com/send_emai.php?subject=hello&body=test')
.然后(()=>{window.location.href=url});
}

“点击该URL”-哪一个?你在报告中提到了三个不同的问题code@JaromandaXonClicked中的此URL:“您的代码很可能会导航到
href
URL,而不是传递给单击功能的URL-我可能错了,单击链接时您看到了什么?为什么你会有一个永远不会被导航到的href?此外,提取可能会发生,也可能不会发生,如果提取确实发生,则不太可能发生任何
。然后
的情况,因为您将导航到一个新页面。我确实希望它导航到href URL。但是我需要它来点击另一个url,这样它就可以给我发送一封关于它的电子邮件,并打开一个新标签?(对我来说)混淆的是3个完全不相关的URL,你的代码在它们之间没有任何连接谢谢-我应该把脚本放在HTM链接下面还是放在我的标题中?任何一个都可以。对于用于多个按钮的脚本,您应该更喜欢
https://www.MyWebsite.com/send_emai.php?subject=hello&body=test