问题描述
我有一个分类广告网站,并且在显示广告的网页上,我正在创建一个向朋友发送小费的表单...
所以任何想要的人都可以将广告的小费发送给某些朋友的电子邮件地址。
我猜表单必须提交给php页面吗?
< form name ='tip'method ='post'action ='tip.php'>
提示某人:< input name =tip_emailtype =textsize =30onfocus =tip_div(1);的onblur = tip_div(2);/>
< input type =submitvalue =Skicka Tips/>
< input type =hiddenname =ad_id/>
< / form>
提交表单时,页面会重新加载...我不想那样...
有没有办法让它不能重新加载并且仍然发送邮件?
最好不用ajax或jquery ...
谢谢
您需要提交ajax请求才能发送电子邮件,而无需重新加载页面。查看
你的代码应该是:
$ b
$(' #submit')。click(function(){
$ .ajax({
url:'send_email.php',
type:'POST',
data:{
email:'[email protected]',
message:'hello world!'
},
success:function(msg){
alert('Email Sent ');
}
});
});
表单将在后台提交给 send_email.php
页面,这将需要处理请求并发送电子邮件。
I have a classifieds website, and on the page where ads are showed, I am creating a "Send a tip to a friend" form...
So anybody who wants can send a tip of the ad to some friends email-adress.
I am guessing the form must be submitted to a php page right?
<form name='tip' method='post' action='tip.php'>
Tip somebody: <input name="tip_email" type="text" size="30" onfocus="tip_div(1);" onblur="tip_div(2);"/>
<input type="submit" value="Skicka Tips"/>
<input type="hidden" name="ad_id" />
</form>
When submitting the form, the page gets reloaded... I don't want that...
Is there any way to make it not reload and still send the mail?Preferrably without ajax or jquery...
Thanks
You'll need to submit an ajax request to send the email without reloading the page. Take a look at http://api.jquery.com/jQuery.ajax/
Your code should be something along the lines of:
$('#submit').click(function() {
$.ajax({
url: 'send_email.php',
type: 'POST',
data: {
email: '[email protected]',
message: 'hello world!'
},
success: function(msg) {
alert('Email Sent');
}
});
});
The form will submit in the background to the send_email.php
page which will need to handle the request and send the email.
这篇关于提交表单而不重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!