gpt4 book ai didi

javascript - 发布方法不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 19:02:10 26 4
gpt4 key购买 nike

我想使用 ajax 使用 post 提交表单数据,因为在提交后的表单 post 中,它会重定向到新页面。

<form id="myContactForm">
<p>
<label for="byour_name">Your name</label><input type="text" name="byour_name" value="" id="byour_name">
</p>
<p>
<label for="byour_email_address">Your email address</label><input type="text" name="byour_email_address" value="" id="byour_email_address">
</p>
<p>
What's on your mind?<br>
<textarea name="Message" rows="10" cols="25"></textarea>
</p>
<p>
<input type="submit" value="Send it!" onClick="sendMail()">
</p>
</form>

function sendMail() {
$.ajax( {
url: "/email",
type: "POST",
data: $("#myContactForm").serialize(),
success: function( response) {
alert(response);
},
error: function() {
alert('failure');
}
});
}

每次我发出请求时,错误函数都会执行。我正在谷歌应用程序引擎上编写应用程序。我不断收到此错误:

self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

我的帖子请求处理程序是:

def post(self):

Content = self.request.get("Message")
byName = self.request.get("byour_name")
byEmailAddress = self.request.get("byour_email_address")

gmailUser = 'id@gmail.com'
gmailPassword = 'password'
dataSend = byName

mail.send_mail(sender = gmailUser,
to = gmailUser,
subject ="Email Sent By : "+ byName + "@" + byEmailAddress,
body = Content)
self.response.out.write(byEmailAddress)

点击提交按钮后,URL 更改为:

http://localhost:8080/?byour_name=username&byour_email_address=userEmail@gmail.com%40gmail.com&Message=mlm%0D%0A#contact

当我发出 get 请求时,有人可以帮助我。但是 post 请求如何更改为 get 请求。

最佳答案

您没有阻止默认提交。从 sendMail 函数返回 false,或者将事件作为参数并对其调用 preventDefault()

关于javascript - 发布方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15759145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com