I am using the following code. Which is submitting fine with php and it appears success ajax action...after of implement AJAX and submitted an email... but in the email doesn't show the email data, it's blank....
我使用以下代码。这是提交与PHP的罚款,它似乎成功ajax行动...实施AJAX和提交电子邮件...但在电子邮件中没有显示电子邮件数据,它是空白....
HTML
HTML
<form id="sForm" action="submit.php" method="get">
<label>your e-mail: </label>
<input type="text" name="email"></input>
<input id="sub" type="submit" />
</form>
<div id="message_ajax"></div>
<div id="error"></div>
jQuery
jQuery的
$("#sub").click(function(){
var datastr = 'email'
$.ajax({
type: 'GET',
url: 'submit.php',
data: datastr,
beforeSend:function(){
$('#message_ajax_wait').append('Loading...');
},
success:function(data){
$('#message_ajax_wait').fadeOut(400);
$("#message_ajax_done").append('done!');
},
error:function(){
$('#error').append('sigh... lets fix... or its server fault');
}
});
return false;
});
Look i removed "return false;" it can show the email data in e-mail inbox, BUT AJAX response didn't work and redirected to ugly php page as submit.php which is coded to send email.
看我删除“return false;”它可以在电子邮件收件箱中显示电子邮件数据,但是AJAX响应不起作用,并重定向到丑陋的php页面,作为submit.php编码发送电子邮件。
Can anyone help me?
谁能帮我?
3 个解决方案
#1
1
You can use the .serialize() method to easily post all the fields within the form. So in your case:
您可以使用.serialize()方法轻松发布表单中的所有字段。所以在你的情况下:
var datastr = $("#sForm").serialize();
Or without adding it to a string first:
或者不首先将其添加到字符串:
$.ajax({
type: 'GET',
url: 'submit.php',
data: $("#sForm").serialize(),
beforeSend:function(){
....
};
#2
1
You are sending the wrong data in the AJAX request. It should work if var datastr = 'email';
is changed to var datastr = 'email=' . $('#email').val();
and you add id="email"
to the email input.
您在AJAX请求中发送了错误的数据。如果var datastr ='email',它应该工作;更改为var datastr ='email ='。 $( '#电子邮件')VAL();并在电子邮件输入中添加id =“email”。
#3
1
try setting your data object to
尝试将数据对象设置为
var data = {email:$("input[name=email]").val()};
$.ajax({
type: 'GET',
url: 'submit.php',
data: data,
beforeSend:function(){
....
};
#1
1
You can use the .serialize() method to easily post all the fields within the form. So in your case:
您可以使用.serialize()方法轻松发布表单中的所有字段。所以在你的情况下:
var datastr = $("#sForm").serialize();
Or without adding it to a string first:
或者不首先将其添加到字符串:
$.ajax({
type: 'GET',
url: 'submit.php',
data: $("#sForm").serialize(),
beforeSend:function(){
....
};
#2
1
You are sending the wrong data in the AJAX request. It should work if var datastr = 'email';
is changed to var datastr = 'email=' . $('#email').val();
and you add id="email"
to the email input.
您在AJAX请求中发送了错误的数据。如果var datastr ='email',它应该工作;更改为var datastr ='email ='。 $( '#电子邮件')VAL();并在电子邮件输入中添加id =“email”。
#3
1
try setting your data object to
尝试将数据对象设置为
var data = {email:$("input[name=email]").val()};
$.ajax({
type: 'GET',
url: 'submit.php',
data: data,
beforeSend:function(){
....
};