我想使用 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
当我提出获取请求时,有人可以帮助我..但是发布请求如何更改以获取请求。